php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

MySQL Invalid date exception

Open koenpunt opened this issue 11 years ago • 4 comments

Depending on your MySQL configuration, errors like this can appear:

PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2014-07-19 09:59:36 UTC' for column 'updated_at' at row 1

The error does make sense, because MySQL does not know about timezone (UTC part).

So I tried to find where it does add the timezone, but yet without success.

This error can be suppressed, (or ignored?) by removing STRICT_TRANS_TABLES from the sql_mode: http://dev.mysql.com/doc/refman/5.1/en/sql-mode.html#sqlmode_strict_trans_tables

koenpunt avatar Jul 19 '14 10:07 koenpunt

Just poking my nose in but isn't this similar to https://github.com/jpfuentes2/php-activerecord/issues/412 ?

willpower232 avatar Jul 19 '14 17:07 willpower232

You can also start mysql server with --sql-mode=ALLOW_INVALID_DATES switch.

tuupola avatar Aug 06 '14 09:08 tuupola

more disturbingly, this is what I pushed #317 over a year ago to fix, but it still hasn't gotten merged. koenpunt is apparently starting to work on it now.

andyleap avatar Dec 08 '14 01:12 andyleap

@andyleap I think he hasn't :)

Why not just setting \ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s'; prior to creating the connection?

It seems to fix the issue for me (after migrating from PHP 5.6 to PHP 7 and from MySQL 5.6 to MySQL 5.7)

rkyoku avatar Feb 03 '18 00:02 rkyoku