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
to solve this problem you have to store result data before use it
$numRecords->execute();
$numRecords->store_result();
that's all
I think the problem is that you're making a new connection in the function, and then not closing it at the end. Why don't you try passing in the existing connection and re-using it?
Another possibility is that you're returning out of the middle of a while loop fetching. You never complete that outer fetch.
This is not related to the original question, but i had the same error-message and this thread is the first hit in Google and it took me a while to figure out what the Problem was, so it May be of use for others:
i'm NOT using mysqli, still using mysql_connect i had some simple querys, but ONE query caused all other querys to fail within the same Connection.
I use mysql 5.7 and php 5.6 i had a table with the data-Type "JSON". obviously, my php-version did not recognize the return value from mysql (php just did not know what to do with the JSON-Format because the built-in mysql-module was too old (at least i think))
for now i changed the JSON-Field-Type to Text (as for now i don't need the native mysql JSON-functionality) and everything works fine
I am using ODBC, and this fix works for me: ODBC -> tab System DSN -> double click to configure my data source -> details -> tab Cursors -> Uncheck [Don't cache results of forward-only cursors] -> click Ok
This is an old question, but none of the posted answers worked in my case, I found that in my case I had selects and updates on a table in my stored procedure, the same table had an update trigger which was being triggered and senging the procedure into an infinite loop. Once the bug was found the error went away.
I call this function every time before using $mysqli->query Works with stored procedures as well.
function clearStoredResults(){
global $mysqli;
do {
if ($res = $mysqli->store_result()) {
$res->free();
}
} while ($mysqli->more_results() && $mysqli->next_result());
}