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

警告: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条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像