Commands out of sync; you can't run this command now

前端 未结 21 2556
庸人自扰
庸人自扰 2020-11-21 11:35

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

相关标签:
21条回答
  • 2020-11-21 12:08

    to solve this problem you have to store result data before use it

    $numRecords->execute();
    
    $numRecords->store_result();
    

    that's all

    0 讨论(0)
  • 2020-11-21 12:08

    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.

    0 讨论(0)
  • 2020-11-21 12:09

    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

    0 讨论(0)
  • 2020-11-21 12:09

    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

    0 讨论(0)
  • 2020-11-21 12:16

    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.

    0 讨论(0)
  • 2020-11-21 12:18

    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());        
    
    }
    
    0 讨论(0)
提交回复
热议问题