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
I solved this problem in my C application - here's how I did it:
Quoting from mysql forums:
This error results when you terminate your query with a semicolon delimiter inside the application. While it is required to terminate a query with a semicolon delimiter when executing it from the command line or in the query browser, remove the delimiter from the query inside your application.
After running my query and dealing with the results [C API: mysql_store_result()], I iterate over any further potentially pending results that occurs via multiple SQL statement execution such as two or more select statements (back to back without dealing with the results).
The fact is that my procedures don't return multiple results but the database doesn't know that until I execute: [C API: mysql_next_result()]. I do this in a loop (for good measure) until it returns non-zero. That's when the current connection handler knows it's okay to execute another query (I cache my handlers to minimize connection overhead).
This is the loop I use:
for(; mysql_next_result(mysql_handler) == 0;)
/* do nothing */;
I don't know PHP but I'm sure it has something similar.