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

后端 未结 3 1038
没有蜡笔的小新
没有蜡笔的小新 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 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

提交回复
热议问题