首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php mysqli嵌套循环中的预准备语句抛出命令或同步错误

php mysqli嵌套循环中的预准备语句抛出命令或同步错误
EN

Stack Overflow用户
提问于 2014-01-11 19:27:42
回答 1查看 482关注 0票数 0

我有以下函数,该函数同时使用for和while循环来执行准备好的语句。但是它作为Commands out of sync; you can't run this command now抛出了错误

下面是我的函数

代码语言:javascript
复制
public function queryProductDetail() {

    $product_info = $this->mysqliengine->prepare("select product_id, sku from product limit 10");
    $product_info->execute();
    $product_info->bind_result($product_id,$sku);

    $product_image = $this->mysqliengine->prepare("insert into product_image(product_id,thumb_image,medium_image,original_image) values(?,?,?,?)") or die($this->mysqliengine->error);
    $product_image->bind_param('isss',$api_product_id, $thumb_image, $medium_image, $original_image);


    while($product_info->fetch()) {
        $rowResult = $this->api->queryProduct(array('serverParams' => array('sku' => $sku, 'usertoken' => USER_TOKEN)));
        foreach($rowResult->result->imagesUrls->Image as $image) {
            $api_product_id = $product_id;
            $thumb_image = $image->smallurl;
            $medium_image = $image->middleurl;
            $original_image = $image->bigurl;
            $product_image->execute();
        }
    }
}

有没有人能告诉我为什么会这样。

这是$product_image->bind_param中的消息Fatal error: Call to a member function bind_param() on a non-object

EN

回答 1

Stack Overflow用户

发布于 2014-01-11 19:30:39

C.5.2.14. Commands out of sync

例如,如果您正在使用mysql_use_result()并试图在调用mysql_free_result()之前执行一个新查询,则可能会发生这种情况。如果您试图执行两个返回数据的查询,而没有在两者之间调用mysql_use_result()或mysql_store_result(),也会发生这种情况。

$product_info->execute()会打开一个mysql资源,这会阻止新的查询。Unbuffered Queries可能是导致该错误的原因。默认情况下,mysqli_stmt::prepare()返回未缓冲的结果:

默认情况下,

预准备语句返回未缓冲的结果集。。。还可以使用mysqli_stmt_store_result()缓冲预准备语句的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21061674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档