Prepared-application passes on original error

I don't see 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 call to say hi", "2009-09-12", "2009-09-12", "1", "1");

Error message:

Fatal error: Cannot pass parameter 8 by reference

+2


source to share


2 answers


I am assuming your method bind_param

is actually mysqli_stmt::bind_param

. If yes: all parameters (except the first one) must be variables passed by reference, so they can be "bound".

As the manual says (emphasis mine):

mysqli_stmt::bind_param

- mysqli_stmt_bind_param

- Holy variables for prepared statement as parameters




This means that you cannot pass a value: you must use variables.

Si, in your case, something like this should do:

$my_var = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, 
   $endDate, $author, $dt, $my_var, $status);

      

+6


source


Found! He would like activeFlag to be a variable. The following works:



$dt = date("Y-m-d");
$flag = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, $flag, $status);
$stmt->execute();

      

0


source







All Articles