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条)

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算