准备好的语句按引用传递错误
我没有看到错误,希望有人能弄清楚:
public static function createMessage($title, $message, $startDate, $endDate, $author, $status){
//$dbConn is now a mysqli instance with a connection to the database foobar
$dbConn = Database::getConnection("foobar");
$stmt = $dbConn->prepare("INSERT into messages(title, msg, date_start, date_end, app_usersID_FK, date_created, activeflag, msg_status) VALUES (?,?,?,?,?,?,?,?)");
if(!$stmt){
throw new Exception("Unable to prepare the statement");
}
$dt = date("Y-m-d");
$stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, 1, $status);
$stmt->execute();
return true;
}
Function call
MessageCenter::createMessage("Hello", "Just Calling to say hi", "2009-09-12", "2009-09-12" 、“1”、“1”);
错误消息是:
致命错误:无法通过引用传递参数 8
I'm not seeing the error and was hoping someone could figure it out:
public static function createMessage($title, $message, $startDate, $endDate, $author, $status){
//$dbConn is now a mysqli instance with a connection to the database foobar
$dbConn = Database::getConnection("foobar");
$stmt = $dbConn->prepare("INSERT into messages(title, msg, date_start, date_end, app_usersID_FK, date_created, activeflag, msg_status) VALUES (?,?,?,?,?,?,?,?)");
if(!$stmt){
throw new Exception("Unable to prepare the statement");
}
$dt = date("Y-m-d");
$stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, 1, $status);
$stmt->execute();
return true;
}
Function call
MessageCenter::createMessage("Hello", "Just calling to say hi", "2009-09-12", "2009-09-12", "1", "1");
Error Message is:
Fatal error: Cannot pass parameter 8 by reference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你的
bind_param
方法实际上是 <代码>mysqli_stmt::bind_param。如果是:每个参数(第一个参数除外)必须是通过引用传递的变量,因此它们可以“绑定”。就像手册所说的(强调我的):
这意味着您不能传递值:您必须使用变量。
Si,就你的情况而言,应该这样做:
I'm guessing your
bind_param
method is actuallymysqli_stmt::bind_param
. If yes : every parameters (except for the first one) must be variables passed by reference, so they can be "binded".Like the manual says (emphasis mine) :
This means you cannot pass a value : you have to use variables.
Si, on your case, something like this should do :
找到了!它希望 activeFlag 成为一个变量。以下作品:
Found it! It wanted activeFlag to be a variable. The following works: