Rumah > pangkalan data > tutorial mysql > PHP date(/Datetime::W3C)插入日期格式提示错误_MySQL

PHP date(/Datetime::W3C)插入日期格式提示错误_MySQL

WBOY
Lepaskan: 2016-06-01 13:11:14
asal
958 orang telah melayarinya

详情如下

 select date('2014-05-16T11:13:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:13:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.02 sec)

mysql> select date('2014-05-16T11:13:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:13:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date('2014-05-16T11:12:57+08:00');
+-----------------------------------+
| date('2014-05-16T11:12:57+08:00') |
+-----------------------------------+
| 2014-05-16 |
+-----------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------------+
| date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------------+
| 2014-05-16 11:13:57 |
+---------------------------------------------------------------+
1 row in set, 1 warning (0.03 sec)

mysql> select date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------------+
| date_format('2014-05-16T11:13:57+08:00', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------------+
| 2014-05-16 11:13:57 |
+---------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

本人mysql版本是5.5.19,执行以上sql这个表明mysql是支持w3c日期格式的。

问题出在那儿呢?最后定位到了mysql可能开启严格检查日期模式,执行

set sql_mode=NO_ENGINE_SUBSTITUTION,这个问题就解决了!!!

不过mysql 重启后这个配置就失效了,最好的方法是修改mysql.ini制空


sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan