PHP: «Comandos no sincronizados» si vuelvo a mysqli :: query () después de una llamada a un procedimiento almacenado de resultados
Tengo un procedimiento almacenado en mi base de datos que devuelve todos los registros en una tabla:
CREATE PROCEDURE showAll()
BEGIN
SELECT * FROM myTable;
END
El SP funciona exactamente como se esperaba. Pero, si lo llamo en un script php y luego trato de consultar la base de datos nuevamente, siempre falla:
// $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>";
}
Notablemente, si cambio las dos consultas (es decir, llamo al procedimiento almacenado al final) funciona sin ningún error. Para cerrar () el resultado antes de la segunda consulta no ayuda. Algunas pistas?
EDITAR: mysqli :: error () es: «Comandos fuera de sincronización; no puedes ejecutar este comando ahora ».