我只是有一个奇怪的准备语句失败,我不知道为什么
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- 错误:命令不同步;你现在不能运行这个命令