PHP: "Commands are not synchronized" if I again mysqli :: query () after calling the stored procedure for providing the results

I have a stored procedure in my db that returns all the records in a table:

CREATE PROCEDURE showAll()
BEGIN
    SELECT * FROM myTable;
END

SP works as expected. But if I call it in a php script and then try to query the database again, it always fails:

// $mysqli is a db connection

// first query:

if (!$t = $mysqli->query("call showAll()"))
    die('Error in the 1st query');

while ($r = $t->fetch_row()) {
    echo $r[0] . "<br>"; // this is ok
}

$t->free(); // EDIT (this doesn't help anyway)

// second query (does the same thing):

if (!$t = $mysqli->query("SELECT * from myTable"))
    die('Error in the 2nd query'); // I always get this error

while ($r = $t->fetch_row()) {
    echo $r[0] . "<br>";
}

It’s great if I change two requests (i.e. I will call the stored procedure at the end), it works without any errors. Closing () the result before the second query does not help. Some clues?

EDIT: mysqli :: error (): "Commands are not synchronized; you cannot run this command now."

+5
source share
2

php.net/manual mysqli.query . , $mysqli- > next_result() $t- > close(). petrus.jvr!

: http://www.php.net/manual/en/mysqli.query.php#102904

+5

@jymian, . , .

$t->free(),

$mysqli->next_result().

, .

+2

All Articles