Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change sql_mode at runtime

Tags:

php

mysql

My MySQL server's sql_mode setting is set to STRICT. I want to change it to TRADITIONAL for a particular application I'm developing. However it's not possible for me to do this at the server level.

Is it possible to change the sql_mode setting at runtime from my PHP scripts?

like image 383
Dave Morris Avatar asked Mar 11 '11 13:03

Dave Morris


People also ask

Can't be set to the value of NO_AUTO_CREATE_USER?

How would one fix this? if you have access to the sed utility, try this command: sed -i 's/NO_AUTO_CREATE_USER//' mysqldump. sql to remove the "NO_AUTO_CREATE_USER" text from your dump file, and replace it with nothing. @pbnelson you should grep for NO_AUTO_CREATE_USER before you do this.

What is @@ sql_mode?

SQL mode (sql_mode) is a MySQL system variable. By means of this varriable the MySQL Server SQL mode is controlled. Many operational characteristics of MySQL Server can be configured by setting the SQL mode.


1 Answers

Hmm this should work

// connect to mysql and call the first query
mysqli_query($conn, "SET SESSION sql_mode = 'TRADITIONAL'");
like image 97
butterbrot Avatar answered Oct 22 '22 02:10

butterbrot