【问题标题】:PDO execute() error with bindParam带有 bindParam 的 PDO 执行()错误
【发布时间】:2015-09-12 08:56:57
【问题描述】:

我找不到这段代码失败的地方

 $username = $_POST["UserID"];
 $password = $_POST["PWD"];
 $sql = 'select COUNT(*) from Staff where UserID = :UserID and PWD = :PWD';
 $result = $cnnEmployee->prepare($sql);
 $result->bindParam(':UsedID',$username, PDO::PARAM_STR)
 $result->bindParam(':PWD',$password, PDO::PARAM_STR)
 $result->execute(); //Error here: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'

但是如果我改成

 $username = $_POST["UserID"];
 $password = $_POST["PWD"];
 $sql = 'select COUNT(*) from Staff where UserID = :UserID and PWD = :PWD';
 $result = $cnnEmployee->prepare($sql);
 $result->execute(array(':UserID'=>$username, ':PWD'=>$password));

它工作正常 请帮我找出我的问题在哪里。

【问题讨论】:

  • 您注意到第一个示例中使用:UsedID 而不是:UserID 的错字了吗?
  • 哦,非常感谢。

标签: php pdo bindparam


【解决方案1】:

当您绑定参数时,您使用:UsedID,但查询中的占位符正在寻找:UserID

【讨论】:

    猜你喜欢
    • 2012-09-05
    • 1970-01-01
    • 2013-06-04
    • 2012-02-04
    • 1970-01-01
    • 2015-12-27
    • 2023-03-28
    • 2011-04-13
    • 2014-05-10
    相关资源
    最近更新 更多