我有以下函数,该函数同时使用for和while循环来执行准备好的语句。但是它作为Commands out of sync; you can't run this command now抛出了错误
下面是我的函数
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
发布于 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()缓冲预准备语句的结果。
https://stackoverflow.com/questions/21061674
复制相似问题