SQLSTATE [HY093]:参数号无效:没有绑定参数,但提供了参数

 拥有勒幷不代表幸福_563 发布于 2023-02-12 12:34

我正在构建一个数据库对象,它将PDO对象与PDOStatement对象连接起来,以便链接可用.基本上我只是把我经常使用的方法,但bindParam给我一个艰难的时间.

private $stmt = null;

...

public function prepare($statement,array $driver_options = array()) {
    if($this->stmt) throw new \Exception('PDO Statement already prepared, no override!');
    $this->stmt = parent::prepare($statement, $driver_options);
    return $this;
}

public function bindParam($place, &$val, $dataType){
    if(!$this->stmt) throw new \Exception('PDO Statement is empty');
    $this->stmt->bindParam($place, $val, $dataType);
    return $this;
}

public function execute(array $params = array()){
    if(!$this->stmt) throw new \Exception('PDO Statement is empty');
    $this->stmt->execute($params);
    return $this;
}

public function fetchAll($pdoFetchType){
    if(!$this->stmt) throw new \Exception('PDO Statement is empty');
    return $this->stmt->fetchAll($pdoFetchType);
}

...

public function getStmt(){
    return $this->stmt;
}

public function clearStmt(){
    $this->stmt = null;
}

我在这段代码中从标题中得到错误:

$i = 0;
$db->prepare('SELECT * FROM users LIMIT ?,1')->bindParam(1, $i, \PDO::PARAM_INT);
while($row = $db->execute()->fetchAll(\PDO::FETCH_ASSOC)){
    echo "
".print_r($row, true)."
"; $i++; }

基本上我发现的关于这个错误的是它在提供变量时bindParam出现null,但$i显然不是null.你能帮我吗?

编辑:也在运行

var_dump($this->stmt->bindParam($place, $val, $dataType));

bindParam方法返回TRUE.从手册:

返回值

成功时返回TRUE,失败时返回FALSE.

它成功但没有绑定参数??? 我觉得我的大脑很快就会爆炸.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有