Mysqli multi-SQL statement execution & lt ;? Php // object creation $ mysqli & nbsp ;=& nbsp; new & nbsp; mysqli ('localhost', & nbsp; 'root', & nbsp; 'nagiosxi ', 'hrsystem'); // connection error if ($ mysqli-& gt; conn mysqli multi-SQL statement execution problem
// Object creation
$ Mysqli = new mysqli ('localhost', 'root', 'nagiosxi', 'hrsystem ');
// Connection error
If ($ mysqli-> connect_error)
{
Die ('connect database error'. mysqli_connect_error ());
}
$ SQL = "insert into login (user, pass, email, type) values ('dengchao1', md5 ('dengchao123'), 'dengchao1 @ gmail.com ', 0 );";
$ SQL. = "insert into login (user1, pass, email, type) values ('dengchao1', md5 ('dengchao123 '), 'dengchao1 @ gmail.com', 0 )";
$ Res = $ mysqli-> multi_query ($ SQL );
If ($ res & $ mysqli-> affected_rows> 0)
{
Echo "insert OK
Rows: ". $ mysqli-> affected_rows;
}
Else
{
// $ Mysqli-> close ();
Die ('Insert error
'. $ Mysqli-> error. $ mysqli-> close ());
}
If (! Is_bool ($ res ))
{
$ Res-> free ();
}
$ SQL = "select * from login ";
$ Res = $ mysqli-> query ($ SQL );
Echo $ mysqli-> error ."
";
If ($ res)
{
While ($ row = $ res-> fetch_row ())
{
Foreach ($ row as $ key => $ val)
{
Echo "-- $ val ";
}
Echo"
";
}
}
If (! Is_bool ($ res ))
{
$ Res-> free ();
}
$ Mysqli-> close ();
?>
Why is the error: Commands out of sync; you can't run this command now
The corresponding query statement is
$ SQL = "select * from login ";
$ Res = $ mysqli-> query ($ SQL );
I am not very puzzled. please answer the question, not Baidu.
------ Solution --------------------
Release the result set of multi_query before querying