【问题标题】:SQL Bound variables errorSQL 绑定变量错误
【发布时间】:2015-05-11 13:04:51
【问题描述】:

我的代码中出现错误。我确定这意味着我的代码的 column=:variable 部分有问题,但我已经检查过了,看不出有什么问题。

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in F:\...

这是代码(第一行很长):

        $stmt = $dbh->prepare("UPDATE item_list SET quantity=:quantity, new_price=:newprice, image_link=:image_link, market_hash_name=:markethashname, last_update='1000-01-01 00:00:00', is_tradable='TEST', old_price=:oldprice WHERE item_name=:itemname AND (image_link IS NULL OR quantity IS NULL OR new_price IS NULL OR market_hash_name IS NULL OR last_update IS NULL OR is_tradable IS NULL OR old_price IS NULL)");
        $sql->bindParam(':quantity', $json2->quantity);
        $sql->bindParam(':newprice', $json2->lowest_price);
        $sql->bindParam('image_link', $image_link_full);
        $sql->bindParam(':markethashname', urlencode($mydata->market_hash_name));
        $sql->bindParam(':oldprice', $json2->lowest_price);
        $stmt->bindValue(':itemname', $mydata->market_name);
        $stmt->execute();

编辑:image_link 需要是 :image_link,仍然出现同样的错误

编辑 2:有很多错误,使用两个名称 $sql 和 $stmt,使用 bindValue 而不是 bindParam

【问题讨论】:

  • image_link 在绑定中应该是:image_link
  • @Alex 谢谢,我刚刚修复了它,但我仍然收到错误。
  • @Alex 你还能看到它应该是什么吗?
  • 你确定$mydata->market_name 吗?你到处使用`$json2->`
  • @Alex 是的,我在代码的其他部分也有这个功能。

标签: mysql bound-variable


【解决方案1】:

您在 bindParam 语句中的“image_link”之前缺少一个冒号“:”。

【讨论】:

  • 感谢您的观看!我修复了它,但我仍然收到错误,所以一定有更多。
  • 你还能看到什么吗?
  • 也许是 bindValue 与 bindParam ??
  • 谢谢,实际上有点错误。编辑问题来解释它。
猜你喜欢
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-16
  • 2020-10-06
  • 2013-11-22
  • 1970-01-01
相关资源
最近更新 更多