简体   繁体   中英

MySQLi prepared insert statement fails

I am updating my PHP to use mysqli:: instead of mysql_* and I have run into an issue with INSERT statements. I have the following statement:

$stmt = $link->prepare("INSERT INTO `table` (`a`, `b`, `c`) VALUES(?, ?, ?)");
$stmt->bind_param("sss", $a, $b, "0");
$stmt->execute();

I have checked $stmt and it is a proper mysqli_stmt object. It is prepared properly, but for some reason, the statement won't execute. I just get a 500 error from my server.

What am I missing?

Edit

I've determined that the issue is coming from the bind_param method.

Edit 2

Okay, so the error PHP is giving me is this:

Fatal error: Cannot pass parameter 4 by reference in...

This points to the line of bind_param

You can't pass a constant to bind_param. Put the value in a variable first:

$status = "0";
$stmt->bind_param("sss", $oid, $cid, $status);
$stmt->execute();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM