How To Set MySql SQL_MODE to ANSI from PHP

2019-07-13 08:36发布

问题:

MySQL Command:

set @session sql_mode = ANSI;

What is the corresponding PHP Command??

This Approach Does Not Seem To Work:

$conn= new mysqli("localhost", "root", "", "DB");
$conn->options(MYSQLI_INIT_COMMAND, "SET SQL_MODE = 'ANSI'"); 

回答1:

It seems that you have missed the scope variable,try this:

SET GLOBAL SQL_MODE = 'ANSI'



回答2:

Does this work for you? (Sorry, can't test at the moment)

$conn->query("set @session sql_mode = ANSI;");


回答3:

I ended up using mysqli_init instead of new mysqli() and everything worked fine.



标签: php mysqli