未捕获错误:在字符串上调用成员函数query()

时间:2017-09-20 16:11:42

标签: php mysql pdo

我是PHP PDO的新手。我一直在努力解决我的代码上的这个错误未捕获错误:在我的眼中调用成员函数查询()代码看起来很好,除非我不知道

我有一个用户注册的登录表单和一个名为 onRegister.php 的文件,该文件使用 manageUsers.php onRegister类创建一个对象使用 manageUsers 类中的方法 getUserInfo 检查用户名的可用性,每次执行此方法中的查询时都会抛出错误

...... manageUsers.php     

include_once('class.database.php');

class manageUsers{

    public $link;

    function __construct(){

        $dbConnect = new dbConnection();
        $this->link = $dbConnect->connect();
        return $this->link;
    }

    function registerUsers($email, $password, $date){

        $query = $this->link->prepare("INSERT INTO users (username,password,date_created) VALUES (?,?,?)");
        $values = array($username,$password,$date);
        $query->execute($values);
        $count = $query->rowCount();
        return $count;

    }

    function loginUser($username, $password){

        $query = $this->link->query("SELECT * FROM users WHERE username='$username' AND password='$password'");
        $rowCount = $query->rowCount();
        return $rowCount;

    }

    function getUserInfo($username){

        $query = $this->link->query("SELECT * FROM users WHERE username  = '$username'");
        $rowCount = $query->rowCount();

        if($rowCount == 1){

            $results = $query->fetchAll();
            return $results;

        }
        else{
            return $rowCount;
        }
    }
}

>

... onRegister.php

<?php

include_once('class.database.php');

class manageUsers{

    public $link;

    function __construct(){

        $dbConnect = new dbConnection();
        $this->link = $dbConnect->connect();
        return $this->link;
    }

    function registerUsers($email, $password, $date){

        $query = $this->link->prepare("INSERT INTO users (username,password,date_created) VALUES (?,?,?)");
        $values = array($username,$password,$date);
        $query->execute($values);
        $count = $query->rowCount();
        return $count;

    }

    function loginUser($username, $password){

        $query = $this->link->query("SELECT * FROM users WHERE username='$username' AND password='$password'");
        $rowCount = $query->rowCount();
        return $rowCount;

    }

    function getUserInfo($username){

        $query = $this->link->query("SELECT * FROM users WHERE username  = '$username'");
        $rowCount = $query->rowCount();

        if($rowCount == 1){

            $results = $query->fetchAll();
            return $results;

        }
        else{
            return $rowCount;
        }
    }
}

&GT;

0 个答案:

没有答案