2

我没有看到错误,希望有人能弄清楚:

 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;
 }

函数调用

MessageCenter::createMessage("Hello", "打电话打个招呼", "2009-09-12", "2009-09-12", "1", "1");

错误信息是:

致命错误:无法通过引用传递参数 8

4

2 回答 2

6

我猜你的bind_param方法实际上是mysqli_stmt::bind_param. 如果是:每个参数(第一个参数除外)必须是通过引用传递的变量,因此它们可以“绑定”。

就像手册说的(强调我的)

mysqli_stmt::bind_param-- -- 将变量作为参数mysqli_stmt_bind_param绑定 到准备好的语句


这意味着您不能传递值:您必须使用变量。

Si,就您而言,应该这样做:

$my_var = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, 
   $endDate, $author, $dt, $my_var, $status);
于 2009-09-02T19:30:12.447 回答
0

找到了!它希望 activeFlag 成为一个变量。以下作品:

$dt = date("Y-m-d");
$flag = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, $flag, $status);
$stmt->execute();
于 2009-09-02T19:30:16.567 回答