为什么`mysqli-> prepare`在`while($ stmt-> fetch())`中失败了

时间:2013-08-08 12:02:10

标签: php mysqli

我只是有一个奇怪的准备声明失败,我不知道为什么

function send_notification($notification_member_ID,$notification_activity_type,$notification_parent_ID,$notification_parent_type){
  global $mysqli;
  $stmt = $mysqli->prepare("INSERT INTO notifications (`notification_member_ID`, `notification_activity_type`, `notification_parent_ID`, `notification_parent_type`) VALUES ( ? , ? , ? , ? )");
  $stmt->bind_param('iiii', $notification_member_ID, $notification_activity_type, $notification_parent_ID, $notification_parent_type);
  if($stmt->execute()){
    return 1;
  }else{
    error_log("!send_notification(mysqli,$notification_member_ID,$notification_activity_type,$notification_parent_ID,$notification_parent_type) at ".date("Y-m-d H:i:s",time())."\n", 3, "{$dir_error_log}/transaction.log");
  }
}

这是我失败的调试尝试

$product_ID=2;
$stmt = $mysqli->prepare("SELECT product_holder_ID FROM market where product_ID=? ");
$stmt->bind_param('i', $product_ID);
$stmt->execute();
$stmt->bind_result($product_holder_ID);
while($stmt->fetch()){
    $mysql->send_notification($product_holder_ID,'1',$product_ID,'1');
}
  

致命错误:在非对象

上调用成员函数bind_param()

虽然我将其移出循环

但我成功了
$product_ID=2;
$stmt = $mysqli->prepare("SELECT product_holder_ID FROM market where product_ID=? ");
$stmt->bind_param('i', $product_ID);
$stmt->execute();
$stmt->bind_result($product_holder_ID);
while($stmt->fetch()){
}
$mysql->send_notification($product_holder_ID,'1',$product_ID,'1');

内部的黑匣子是什么让它在第一次尝试时出错?


更多信息:

$ mysqli- 错误:命令不同步;你现在不能运行这个命令

0 个答案:

没有答案