"Commands are not synchronized, you cannot run this command now" - mysqli :: multi_query is called

I run multiple deletes via mysqli :: multi_query and run the following query on a line. The following error is called.

Error - SQLSTATE HY000. Sql error: Commands out of sync; you can't run this command now 

Do I need to somehow clear the multiquark so that it does not spoil my next request? What is the reason for this error?

And this is how I run my multiquery

 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 for Windows 7

+8
mysqli multi-query
source share
3 answers

Using mysqli :: multi_query , you run queries, but before you move, you need to process the results of these queries. The page describes various ways of processing the results. After processing, you will be able to complete other requests.

The error message you encounter is actually explained a little better on the mysqli :: query page (although keep in mind that mysqli :: query does not return a result object in this instance as you are doing the deletion).

You could, of course, change multi_query to several separate queries, I don’t know what are the pros and cons of each approach.

+10
source share

This helped me remove the "Commands out of sync" error:

 do { $mysqli_conn_obj->use_result(); }while( $mysqli_conn_obj->more_results() && $mysqli_conn_obj->next_result() ); 

Add this code immediately after calling multi_query, it will use the result sets and fix the error.

+9
source share

Seva code is most likely to fix your problem if you use a procedural style like me use this

 do { if ($result = mysqli_store_result($connect)) { mysqli_free_result($result); } } while (mysqli_next_result($connect)); 
-one
source share

All Articles