doujiu3768 2013-07-24 17:46
浏览 70

PHP:变量数与预准备语句中的参数数量不匹配

I'm getting the following error message in my PHP script;

mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement

But here is the relevant code:

$con = mysqli_connect( $db_url, $db_user, $db_pwd, $db );
$sql = "SELECT * FROM problems WHERE mrn=?";

$stmt = mysqli_prepare( $con, $sql );
mysqli_stmt_bind_param( $stmt, 'i', $sent_mrn );

It points me to the last line there. Am I missing something really obvious? There is only one parameter in the SQL query and I'm binding only one variable! (I know some people will suggest I use PDO, but I gotta use mysqli at the moment)

  • 写回答

2条回答 默认 最新

  • dongshang1979 2013-07-24 17:52
    关注

    When using procedural functions (as opposed to object-oriented), you must first call mysqli_stmt_init() to get the statement object. Then you call mysqli_prepare with this statement as the first parameter, NOT the connection as you are currently doing. Also you don't need the return value of mysqli_prepare unless you're meticulously checking for error conditions. Its return value is NOT passed to mysqli_stmt_bind_param, but rather the statement returned from mysqli_stmt_init().

    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测