MYSQL incorrect DATETIME format

前端 未结 4 1792
醉酒成梦
醉酒成梦 2020-12-09 16:15

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

相关标签:
4条回答
  • 2020-12-09 16:54

    If it exists, you can try removing STRICT_TRANS_TABLES from sql-mode in your 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 causes 500 Internal Server Error - Incorrect datetime value (AuthPuppy Bug #907203)
    0 讨论(0)
  • 2020-12-09 16:56

    This is caused by Zend not setting your timestamp format to one that matches what MySQL is expecting. You could disable STRICT mode in MySQL, but this is a hack and not a solution (MySQL will attempt to guess what the date you're entering is).

    In Zend you can set the datetime format to what MySQL is expecting to solve this:

    $log = new Zend_Log ();
    $log->setTimestampFormat("Y-m-d H:i:s");
    
    0 讨论(0)
  • 2020-12-09 17:10

    Date constants in zend are determined from sniffing out locale in this order (form zend_locale comments)

    1. Given Locale
    2. HTTP Client
    3. Server Environment
    4. Framework Standard
    

    I'm thinking the difference between the two systems is going to be reflected in the Server Environment.

    To correct and avoid this problem in the future you can specify the locale options within your application.ini using these configuration directive.

    resources.locale.default = <DEFAULT_LOCALE>
    resources.locale.force = false
    resources.locale.registry_key = "Zend_Locale"
    

    The locale should be set to a string like en_US

    Zend_Locale specificly sniffs the locale from the environment from a call to setlocale and parsing the results.

    0 讨论(0)
  • 2020-12-09 17:15

    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; set global sql_mode=NO_ENGINE_SUBSTITUTION;

    Thus removing STRICT_TRANS_TABLES

    ------this answer works

    0 讨论(0)
提交回复
热议问题