PHP: «Comandos fora de sincronia» se eu mysqli :: query () novamente após uma chamada para um procedimento armazenado que fornece resultados
Eu tenho um procedimento armazenado no meu db que retorna todos os registros em uma tabela:
CREATE PROCEDURE showAll()
BEGIN
SELECT * FROM myTable;
END
O SP funciona da maneira esperada. Mas, se eu o chamar em um script php e tentar consultar o banco de dados novamente, ele sempre falha:
// $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>";
}
Notável, se eu trocar as duas consultas (ou seja, eu chamo o procedimento armazenado no final), ele funciona sem nenhum erro. Fechar () o resultado antes da segunda consulta não ajuda. Algumas dicas?
EDIT: mysqli :: error () é: «Comandos fora de sincronia; você não pode executar este comando agora ».