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

前端 未结 21 2559
庸人自扰
庸人自扰 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:07

    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.

提交回复
热议问题