无法在预准备语句中比较mysql中的值

时间:2010-03-23 20:57:48

标签: php mysql oop pdo prepared-statement

我似乎无法将此连接到数据库,以便我可以运行我准备好的语句。有没有人知道我忘记了什么?

private function check_credentials($plain_username, $password)
    {
    global $dbcon;

    $ac = new ac();
    $ac->dbconnect();
    $userid = $dbcon->prepare('SELECT id FROM users WHERE username = :username AND password = :password LIMIT 1');
    $userid->bindParam(':username', $plain_username);
    $userid->bindParam(':password', $password);
    $userid->execute();

    $id = $userid->fetch();
    Return $id;
    }

编辑:我将SQL查询从SELECT FROM查询更改为INSERT INTO查询并且工作正常。到底是怎么回事?

1 个答案:

答案 0 :(得分:1)

重新格式化堆栈回溯:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php:61
Stack trace:
#0 E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php(61): PDOStatement->execute(Array)
#1 E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php(34): ac->check_credentials('joe', '94a02c32b6ff629...')
#2 E:\PortableApps\xampp\htdocs\SN\UI\UIclass.php(17): ac->authentication()
#3 E:\PortableApps\xampp\htdocs\SN\index.php(4): ui->start()
#4 {main} thrown in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php on line 61

你有没有理由在check_credentials函数中实例化一个新的ac对象?鉴于check_credentials已经是ac的方法,这看起来很奇怪。 dbconnect是否会覆盖全局dbcon