I am running multiple deletes through mysqli::multi_query
and it is messing up the next query in line. The following error is being thrown.
Error - SQLSTATE HY000.
Sql error: Commands out of sync; you can't run this command now
Do I need to somehow clear the multi query so it doesn't mess with my next query? What is the cause of this error?
And this is how I am running my multi query:
function deleteSomeTables($args) {
$sql = 'delete 1;delete another;';
if ($database->multi_query($sql)) {
return true;
} else {
return false;
}
}
I am using a recent version of Xampp on windows 7
Multiple statements or multi queries must be executed with mysqli::multi_query(). The individual statements of the statement string are separated by semicolon. Then, all result sets returned by the executed statements must be fetched.
The query() / mysqli_query() function performs a query against a database.
MySQLi (MySQL Improved) provides procedural and object oriented interface to data and its management. The i extension MySQL functions allows the user to access its database servers.
Seva's code will most likely fix your issue, if you're using procedural style like me, use this
do {
if ($result = mysqli_store_result($connect)) {
mysqli_free_result($result);
}
} while (mysqli_next_result($connect));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With