Mysql PDO'SQLSTATE[HY093]:参数编号无效:绑定变量的编号与令牌的编号不匹配

Mysql PDO'SQLSTATE[HY093]:参数编号无效:绑定变量的编号与令牌的编号不匹配,mysql,pdo,Mysql,Pdo,我看到许多人出于各种不同的原因发出了同样的信息,但看不到任何与我的具体情况相关的解决方案,从表面上看,这是一个非常简单的解决方案。是的,我的密码是md5,应该更改,但我不认为这是问题所在 我希望有人能指出为什么第一行代码有效而第二行代码无效。在每种情况下,只有一行符合表中的标准 <?php // Include database class include 'DBClass.php'; // Instantiate database. $db = new DBClass(); //*

我看到许多人出于各种不同的原因发出了同样的信息,但看不到任何与我的具体情况相关的解决方案,从表面上看,这是一个非常简单的解决方案。是的,我的密码是md5,应该更改,但我不认为这是问题所在

我希望有人能指出为什么第一行代码有效而第二行代码无效。在每种情况下,只有一行符合表中的标准

<?php

// Include database class
include 'DBClass.php';

// Instantiate database.
$db = new DBClass();

//***********************
// This works
//***********************

$em = 'admin@infin8integr8.com';
$sid = 39;
$db->query("select ufname,ulname from users where uemail = :em and sub_id = :sb");
$db->bind(':em', $em);
$db->bind(':sb', $sid);
$row = $db->single();

echo $row['ufname'].'  '.$row['ulname'].'<br>';

//***************************
// This returns the error 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\wamp\www\pdo\DBClass.php on line 85
//*****************************

//Line 85 in DBClass is "return $this->stmt->execute();" in
    //public function execute(){
        //return $this->stmt->execute();
    //}

$userid = 'f534983b255eb2820bf3ba1438ddcf65';
$password = '0bfd2660362f242169d11e33f7affe0a';
$db->query = ("select ufname,ulname from users where username = :vuid and upwd = :vpwd");
$db->bind(':vuid', $userid);
$db->bind(':vpwd', $password);
$row = $db->single();

echo $row['ufname'].' * '.$row['ulname'].'<br>';

?>

The relevant class code is:-
<?php
class DBClass{

    private $host      = 'localhost';
    private $user      = '<user>';
    private $pass      = '<password>';
    private $dbname    = 'infinint_infin8';

    private $dbh;
    private $error;
    private $stmt;

    public function __construct(){
        // Set DSN
        $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
       // Set options
        $options = array(
            PDO::ATTR_PERSISTENT    => true,
            PDO::ATTR_ERRMODE       => PDO::ERRMODE_EXCEPTION,
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
        // Create a new PDO instanace
        try{
            $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
        }
        // Catch any errors
        catch(PDOException $e){
            $this->error = $e->getMessage();
        }
    }

    public function query($query){
        $this->stmt = $this->dbh->prepare($query);
    }   

    public function bind($param, $value, $type = null){
        if (is_null($type)) {
            switch (true) {
                case is_int($value):
                    $type = PDO::PARAM_INT;
                    break;
                case is_bool($value):
                    $type = PDO::PARAM_BOOL;
                    break;
                case is_null($value):
                    $type = PDO::PARAM_NULL;
                    break;
                default:
                    $type = PDO::PARAM_STR;
            }
        }
        $this->stmt->bindValue($param, $value, $type);
    }

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


    public function resultset(){
        $this->execute();
        return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
    }

    public function single(){
        $this->execute();
        return $this->stmt->fetch(PDO::FETCH_ASSOC);
    }   
}
?>

$db->bind应该是$db->bindParam$db->bind是上述代码中包含的我的DBClass中使用bindValue的方法。问题是,它可以完美地处理一组绑定参数,但不能处理另一组绑定参数,我无法解释原因。已解析-$db->query=从username=:vuid和upwd=:vpwd;应该是$db->queryselect ufname,ulname,来自username=:vuid和upwd=:vpwd的用户;