I want to excute two update sql by using $mysqli->multi_query($sql);But I just get this error info below:
PHP message: UPDATE table1 SET status=1;UPDATE table2 SET name='b'|Commands out of sync; you can't run this command now" while reading response header from upstream,
When I run the query string manually in phpmyadmin, everything works fine as it should.
there is my code:
$mysqli = new MySQLi(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
$mysqli->query("set names utf8");
$sql = "UPDATE table1 SET status=1;UPDATE table2 SET name='b";
if ($mysqli->multi_query($sql))
{
do {
$mysqli->use_result();
} while ($mysqli->more_results() && $mysqli->next_result());
} else {
error_log($sql."|".mysqli_error($mysqli));
return false;
}
Is there any wrong with my code?
================================
I have resolve my question by using this code:
$mysqli = new MySQLi(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
$mysqli->query("set names utf8");
$sql = "UPDATE table1 SET status=1;UPDATE table2 SET name='b";
if ($mysqli->multi_query($sql))
{
do {
$res = $mysqli->use_result();
mysqli_free_result($res);
} while ($mysqli->more_results() && $mysqli->next_result());
} else {
error_log($sql."|".mysqli_error($mysqli));
return false;
}