PHP警告:mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不匹配 [英] PHP Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

查看:114
本文介绍了PHP警告:mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定为什么我收到此PHP警告消息.似乎在prepared语句中有四个参数,在bind_param()中也有四个变量.谢谢你的帮助!

Not sure why I'm getting this PHP warning message. It appears there are four parameters in the prepared statement, and also four variables in 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);
   [...]
}

这些行没有任何意义!如果要使用参数,则必须将它们用于where条件或类似条件,就像:

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:

$mysqli->prepare("SELECT * FROM back_issues WHERE url =? AND month =? AND year =? and cover_image = ?");
$stmt->bind_param("ssis", $url, $month, $year, $cover_image);

如果没有任何占位符与参数绑定,则bind_param()方法将产生您正在运行的错误.此外,该IF语句应该做什么? 如果要验证该查询是否产生任何结果,则必须先运行它,然后再进行验证.

If you don't have any placeholder to bind with parameters, bind_param() method will produce the error you're running throug. Moreover, what that IF statement supposed to do? If you want to verify if that query produce any result, you have first to run it and, then, to verify.

这篇关于PHP警告:mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆