MYSQL DATETIME 格式不正确 [英] MYSQL incorrect DATETIME format

查看:41
本文介绍了MYSQL DATETIME 格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 Doctrine 1 的应用程序,我通过 new Zend_Date->getIso() 为对象生成 update_datetime 字段.多年来它工作得很好,但现在我有了一个新笔记本,Doctrine 尝试将 DATETIME 字段作为字符串插入 "2013-07-12T03:00:00+07:00" 而不是普通的 MySQL 日期时间格式 "2013-07-12 00:00:00" 这很奇怪.

I have an app with Doctrine 1 and I generate update_datetime fields for objects via new Zend_Date->getIso(). It worked just fine for years, but now I got a new notebook and Doctrine tries to insert a DATETIME fields as a string "2013-07-12T03:00:00+07:00" instead of normal MySQL datetime format "2013-07-12 00:00:00" which is totally weird.

相同的代码在另一台计算机上运行良好.一切都几乎相同——MySQL 5.6.12,PHP 5.3.15 都在.知道我应该去哪里看吗?

The very same code runs just fine on another computer. Everything is nearly identical – MySQL 5.6.12, PHP 5.3.15 on both. Any idea where should I look?

致命错误:未捕获的异常 'Doctrine_Connection_Mysql_Exception' 带有消息 'SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:'2013-07-12T03:00:00+07:00' 列 'nextrun'在第 1 行'在 library/Doctrine/Connection.php:1083

更新

好的,在 StackOverflow 社区的帮助下,我终于解决了.问题出在 sql_mode 变量中的 STRICT_TRANS_TABLES 上.但是在 /etc/my.cnf 中更改它似乎还不够,所以我不得不运行 mysql -uroot 并输入以下内容:

Ok with the help from StackOverflow community I finally solved it. The problem was with STRICT_TRANS_TABLES in sql_mode variable. But changing it in /etc/my.cnf seemed not enough, so I had to run mysql -uroot and type the following:

设置 sql_mode=NO_ENGINE_SUBSTITUTION;设置全局 sql_mode=NO_ENGINE_SUBSTITUTION;

因此删除 STRICT_TRANS_TABLES

更新2如何永远摆脱 STRICT?如何在 MySQL 中摆脱 STRICT SQL 模式

UPDATE2 How to get rid of STRICT forever? How to get rid of STRICT SQL mode in MySQL

推荐答案

如果存在,您可以尝试在 my.ini 中从 sql-mode 中删除 STRICT_TRANS_TABLES.

If it exists, you can try removing STRICT_TRANS_TABLES from sql-mode in your my.ini.

这可能会导致此错误,日期时间字符串值包含您尚未转换为 mysql 日期时间的格式.此 my.ini 更改已报告为以下方面的修复:

This can cause this error with a datetime string value containing the format you have not being converted to mysql datetime. This my.ini change was reported as a fix in:

这篇关于MYSQL DATETIME 格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆