phpmysqlselectmysqlimulti-query

When i have a mysqli_multi_query followed by a mysqli_query, the second query fails


I have a self calling php form that is supposed to update the database, then display the changes. This is the general idea of what the code looks like:

IF($condition)
    mysqli_multi_query($dbc,$multiple_update_query_str);
$result = mysqli_query($dbc,$select_query);
while($row = mysqli_fetch_array($result))
    echo    $row[0] . " " . $row[1] . " " . $row[2] . "<br>";

The first time, when the $condition is false, the select query works perfectly. Then when the $condition is true, the update occurs on the database, but the select query fails.

My first thought was that php server was getting ahead of the mySQL server, so I used sleep(5) before exiting the if statement, but the select still failed.

I even wrote a very basic php file that was almost exactly this code. It had the same problem. Is there something I am missing?


Solution

  • before you can use mysqli_query you must retrieve all the results of the multy_query to unlock the link connection

    try:

    if($condition){
        mysqli_multi_query($dbc,$multiple_update_query_str);
        while(mysqli_next_result($dbc)){;}
    }