問題描述
我有一個帶有 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:
set 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:
- PING 導致 500 內部服務器錯誤 - 日期時間值不正確(AuthPuppy 錯誤 #907203)
- PING causes 500 Internal Server Error - Incorrect datetime value (AuthPuppy Bug #907203)
這篇關于MYSQL 不正確的 DATETIME 格式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!