繁体   English   中英

PHP:«命令不同步»如果我调用结果存储过程后再次mysqli :: query()

[英]PHP: «Commands out of sync» if I mysqli::query() again after a call to a results-giving stored procedure

我的数据库中有一个存储过程,它返回表中的所有记录:

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()是:«命令不同步; 你现在不能运行这个命令»。

关于mysqli.query的php.net / manual条目的评论已经更新,现在包括一个答案。 总而言之,在$ t-> close()之后调用$ mysqli-> next_result()。 感谢petrus.jvr!

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

@jymian,你的答案不明确。 请清楚表达。

使用$t->free()释放结果集后,

调用$mysqli->next_result()

以上调用将为下一个结果集做准备,您不会出现同步错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM