Php 为什么`mysqli->;在($stmt->;fetch()时准备“内部失败”)`

Php 为什么`mysqli->;在($stmt->;fetch()时准备“内部失败”)`,php,mysqli,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_memb

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

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-
错误:命令不同步;您现在无法运行此命令

为什么要记录大量无用的数据,而不是$mysqli->错误,这实际上解释了prepare的错误?我认为您应该传递
global$mysqli编码到函数中,以确保该函数可用。甚至可以解决你的问题。我不知道。有两个
bind_参数
s。哪一个抛出错误?它是函数throw error中的bind参数,我已经添加了$mysqli->error输出