警告:PDOStatement :: bindValue():SQLSTATE [HY093]:无效的参数编号:列/参数基于1 [英] Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based

查看:187
本文介绍了警告:PDOStatement :: bindValue():SQLSTATE [HY093]:无效的参数编号:列/参数基于1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使query函数如下:

I'm trying to make a query function as follow :

public function Query( $sql, $params = array() ) {
        $this->error = false;

        if ( $this->query = $this->pdo->prepare( $sql ) ) {
            for ( $i = 0, $size = count( $params ); $i < $size; $i ++ ) {
                echo $i;
                $this->query->bindValue( $i, $params[ $i ] );
            }

            if ( $this->query->execute() ) {
                echo 'suc';
            }
        }
    }

并这样称呼它:

$mysql->Query( "SELECT * FROM `client_info` WHERE `name` = ? AND `password`= ?", array(
    'test',
    'test'
) );

结果是:

Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

我不知道这里出了什么问题,一切都应该没问题,应该可以正常工作!

I have no clue what's wrong here , everything supposed to be fine and it should work!!

推荐答案

 $i = 0

还有

警告:PDOStatement :: bindValue():SQLSTATE [HY093]:无效的参数编号:列/参数基于1.

Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based

比较这两件事,您会发现$i必须从1开始,而不是0.

Compare those two things, you will notice that your $i has to start at 1, not 0.

这也可以从 PHP手册

参数

参数标识符.对于使用命名占位符的预备语句,这将是:name形式的参数名称. 对于使用问号占位符的已准备好的语句,这将是参数的1索引位置.

Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.

这篇关于警告:PDOStatement :: bindValue():SQLSTATE [HY093]:无效的参数编号:列/参数基于1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆