【问题标题】:Error with binding variables绑定变量错误
【发布时间】:2015-07-20 03:19:22
【问题描述】:

我正在编写的准备好的语句中出现错误...

 Number of elements in type definition string doesn't match number of bind variables on line 33. Create Topic Insert bind_param() failed:

我唯一能想到的是因为NOW() 字段,但我认为不需要为此设置变量?

我是否明显遗漏了什么或可能导致此错误的原因?

//Prepared INSERT stmt for the forum topic
    $stmt = $con->prepare("INSERT INTO forum_topics (`category_id`, `topic_title`, `topic_creator`, `topic_date`, `topic_reply_date`) 
    VALUES(?, ?, ?, NOW(), NOW())");
    if ( !$stmt || $con->error ) {
        die('Create Topic Insert prepare() failed: ' . htmlspecialchars($con->error));
    }
    if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {
        die('Create Topic Insert bind_param() failed: ' . htmlspecialchars($stmt->error));
    }
    if(!$stmt->execute()) {
        die('Create Topic Insert execute() failed: ' . htmlspecialchars($stmt->error));
    }

【问题讨论】:

  • U 正在绑定 3 ... sss

标签: php mysql prepared-statement


【解决方案1】:

mysqli_stmt::bind_param -- mysqli_stmt_bind_param -- 将变量绑定到准备好的语句作为参数

所以在你的 bind_param 中,你需要插入 5 个参数。

【讨论】:

    【解决方案2】:

    我解决了这个问题。我试图绑定NOW() 字段。我将代码行更改为..

      if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {
    

    现在可以完美运行了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2020-10-06
      • 2013-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多