PHP 插入 SQL 日期
PHP Insert SQL date
我有这个代码:
$date = '1991-08-13';
$sql = "INSERT into TABLEA
(nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas)
VALUES
('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, $date, 'ShhhHH');";
我的问题是下一个:
当我插入 $date 的值时:1991-13-08
但在数据库中出现:0000-00-00
我看过其他带有解决方案的帖子,例如:STR_TO_DATE()
但它对我不起作用,它会插入 NULL。还有其他解决方案吗?
编辑:缺少:$date 中的“”(应该是:“$date”)感谢您的更正! (:
请用单引号将 $date 括起来,例如
$sql = "INSERT into TABLEA (nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas) VALUES ('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, '$date', 'ShhhHH');";
也许你可以这样试试:
$date = '1991-08-13'; //yyyy-mm-dd
$sql = "INSERT into TABLEA
(nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas)
VALUES
('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, '$date', 'ShhhHH');";
使用Str_to_date
Str_to_date('1991-13-08','%Y-%d-%m')
或者试试这个:-
$sql = "INSERT into TABLEA (nombre, apellido1, apellido2,
direccion, codigoPostal,fechaNacimiento, notas)
VALUES ('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr',
86486, Str_to_date("1991-13-08","%Y-%d-%m"), 'ShhhHH');";
我有这个代码:
$date = '1991-08-13';
$sql = "INSERT into TABLEA
(nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas)
VALUES
('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, $date, 'ShhhHH');";
我的问题是下一个:
当我插入 $date 的值时:1991-13-08
但在数据库中出现:0000-00-00
我看过其他带有解决方案的帖子,例如:STR_TO_DATE()
但它对我不起作用,它会插入 NULL。还有其他解决方案吗?
编辑:缺少:$date 中的“”(应该是:“$date”)感谢您的更正! (:
请用单引号将 $date 括起来,例如
$sql = "INSERT into TABLEA (nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas) VALUES ('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, '$date', 'ShhhHH');";
也许你可以这样试试:
$date = '1991-08-13'; //yyyy-mm-dd
$sql = "INSERT into TABLEA
(nombre, apellido1, apellido2, direccion, codigoPostal,fechaNacimiento, notas)
VALUES
('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr', 86486, '$date', 'ShhhHH');";
使用Str_to_date
Str_to_date('1991-13-08','%Y-%d-%m')
或者试试这个:-
$sql = "INSERT into TABLEA (nombre, apellido1, apellido2,
direccion, codigoPostal,fechaNacimiento, notas)
VALUES ('agds', 'asdgff', 'gerth', 'dfghdfghd efdgvwr',
86486, Str_to_date("1991-13-08","%Y-%d-%m"), 'ShhhHH');";