[英]PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
Not sure why I'm getting this PHP warning message.不知道为什么我会收到此 PHP 警告消息。 It appears there are four parameters in the prepared statement, and also four variables in bind_param().
看起来在准备好的语句中有四个参数,并且在 bind_param() 中有四个变量。 Thanks for any help!
谢谢你的帮助!
if($stmt = $mysqli -> prepare("SELECT url, month, year, cover_image FROM back_issues ORDER BY year DESC, month DESC")) {
$stmt -> bind_param("ssis", $url, $month, $year, $cover_image);
$stmt -> execute();
$stmt -> bind_result($url, $month, $year, $cover_image);
$stmt -> fetch();
while ($stmt->fetch()) {
echo "<li class='item'><a href='$url'><img src='$cover_image' alt='$cover_image' width='' height='' /></a><br /><span class='monthIssue'>$month $year</span></li>";
}
$stmt -> close();
$mysqli -> close();
}
if($stmt = $mysqli -> prepare("SELECT url, month, year, cover_image FROM back_issues ORDER BY year DESC, month DESC")) {
$stmt -> bind_param("ssis", $url, $month, $year, $cover_image);
[...]
}
These lines don't make any sense!这些线没有任何意义! If you want to use parameters, you have to use them into a
where
condition or similar, pretty much like:如果要使用参数,则必须将它们用于
where
条件或类似条件,非常类似于:
$mysqli->prepare("SELECT * FROM back_issues WHERE url =? AND month =? AND year =? and cover_image = ?");
$stmt->bind_param("ssis", $url, $month, $year, $cover_image);
If you don't have any placeholder to bind with parameters, bind_param()
method will produce the error you're running through.如果您没有任何占位符与参数绑定,则
bind_param()
方法将产生您正在运行的错误。 Moreover, what that IF statement supposed to do?此外,IF 语句应该做什么? If you want to verify if that query produces any result, you have first to run it and, then, to verify.
如果要验证该查询是否产生任何结果,则必须先运行它,然后再进行验证。
You do not need to bind parameters in this case.在这种情况下,您不需要绑定参数。 Placeholders are used for the values in an INSERT statement, or in a WHERE clause.
占位符用于 INSERT 语句或 WHERE 子句中的值。 (Note that placeholders are not allowed for identifiers, such as the column names in your statement.) A valid, simplified statement with placeholders would look like:
(请注意,标识符不允许使用占位符,例如语句中的列名。)带有占位符的有效简化语句如下所示:
"SELECT url, cover_image FROM back_issues WHERE month = ? and year = ?"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.