doujing2497 2015-01-24 10:40
浏览 192
已采纳

警告:PDOStatement :: bindValue():SQLSTATE [HY093]:参数号无效:列/参数从1开始

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';
            }
        }
    }

and call it like this :

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

and the result is :

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!!

  • 写回答

2条回答 默认 最新

  • dongzhan3937 2015-01-24 10:43
    关注
     $i = 0
    

    And

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

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

    This can also be confirmed from the PHP Manual

    parameter

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动