In my case I discovered some “0000–00–00” dates in my mysql database so I want to run this command when a connection is established to prevent it:
I could probably do it with
but there is maybe some better way in Doctrine?
Sure enough this works. Is it the best approach?
kdyby.doctrine: driverOptions: # Prevent dates like 0000-00-00. # 1002 is \PDO::MYSQL_ATTR_INIT_COMMAND 1002: "SET sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE';"
Beware that you need to use
driverOptions, not just
options. You don't need to bother with
\PDO::ATTR_ERRMODE because Doctrine sets that to exception by
EDIT: It's probably a bit better to use
SET sql_mode='TRADITIONAL'; to enable some additional strict