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

后端 未结 3 1037
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 15:17

In my db I have some stored procedures.

I want to call the one of them, and according to the results I get from this procedure, i will determine weather to call the

相关标签:
3条回答
  • 2020-12-06 15:56

    Every stored procedure returns at least two results

    • one (or many) actual results
    • one empty result to tell the client there are no more results.

    You have to use mysqli_more_results()/mysqli_next_result() to clean them.

    If your procedure returns only one result, or you just don't want any extra results but the first one, you can clean up the results queue with this code snippet:

    while($mysqli->more_results())
    {
        $mysqli->next_result();
        if($res = $mysqli->store_result())
        {
            $res->free(); 
        }
    }
    
    0 讨论(0)
  • 2020-12-06 15:59

    re connect database $this->db->reconnect(); // likes in codeigniter

    0 讨论(0)
  • 2020-12-06 16:07

    The currently accepted answer wont work as-is, i think next_result() should not be called before the first result.

    This is an example that does work:

    if (!$mysqli->multi_query("CALL p()")) {
        echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
    }
    
    do {
        if ($res = $mysqli->store_result()) {
            printf("---\n");
            var_dump($res->fetch_all());
            $res->free();
        } else {
            if ($mysqli->errno) {
                echo "Store failed: (" . $mysqli->errno . ") " . $mysqli->error;
            }
        }
    } while ($mysqli->more_results() && $mysqli->next_result());
    

    From the PHP manual http://php.net/manual/en/mysqli.quickstart.stored-procedures.php

    0 讨论(0)
提交回复
热议问题