MySQLi准备的插入语句失败 [英] MySQLi prepared insert statement fails
问题描述
我正在更新PHP以使用mysqli::
而不是mysql_*
,并且遇到了INSERT
语句问题.我有以下说法:
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();
我检查了$stmt
,它是一个正确的mysqli_stmt
对象.它已经准备妥当,但是由于某种原因,该语句将无法执行.我刚从服务器收到500错误.
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.
我想念什么?
修改
我确定问题出在bind_param
方法上.
I've determined that the issue is coming from the bind_param
method.
编辑2
好的,所以PHP给我的错误是这样的:
Okay, so the error PHP is giving me is this:
致命错误:无法在...中通过引用传递参数4.
Fatal error: Cannot pass parameter 4 by reference in...
这指向bind_param的行
This points to the line of bind_param
推荐答案
您不能将常量传递给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();
这篇关于MySQLi准备的插入语句失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!