How can I set the SQL mode while using PDO?

Viewed 15417

I am trying to set SQL modes, I can't figure out how to do it using PDO. I am trying to set Traditional mode in MySQL and not allow invalid dates.

Can anyone help?

4 Answers

Use this to clear the sql_mode variable:

$db_conn->query("SET SESSION sql_mode=''")->execute();

Or this to remove a specific item from it:

$db_conn->query("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'WRITE_HERE_THE_NAME',''));")->execute();

If you want to make the change global, you would need to have some admin privileges.

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'WRITE_HERE_THE_NAME',''));
Related