I am trying to execute my PHP code, which calls two MySQL queries via mysqli, and get the error \"Commands out of sync; you can\'t run this command now\".
Here is th
Just for reference i had this problem mixing both multi_query
and query
in the same code:
$connection->multi_query($query);
...
$connection->query($otherQuery);
Which for what i read had unconsumed results pending, therefore causing in the mentioned error.
I solved it with a loop consuming all the results of the multi_query
:
$connection->multi_query($query);
while ($connection->next_result()); // <--- solves the problem
...
$connection->query($otherQuery);
In my case all the queries in the multi_query
where inserts so i had no interest in the results themselves.