etu*_*rdu 6 php mysqli stored-procedures
我的数据库中有一个存储过程,它返回表中的所有记录:
CREATE PROCEDURE showAll()
BEGIN
    SELECT * FROM myTable;
END
SP的工作方式与预期一致.但是,如果我在php脚本中调用它,然后我尝试再次查询数据库,它总是失败:
// $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>";
}
值得注意的是,如果我交换了两个查询(即我最后调用了存储过程),它的工作没有任何错误.要在第二个查询之前关闭()结果没有帮助.一些提示?
编辑:mysqli :: error()是:«命令不同步; 你现在不能运行这个命令».
小智 5
关于mysqli.query的php.net/manual条目的评论已经更新,现在包括一个答案.总而言之,在$ t-> close()之后调用$ mysqli-> next_result().感谢petrus.jvr!
链接:http://www.php.net/manual/en/mysqli.query.php#102904