打电话给会员功能

时间:2014-11-19 02:21:29

标签: php oop pdo

此代码出错:致命错误:在第32行的D:\ ProgramFile \ Xampp \ htdocs \ site \ shop \ class \ DB.php中的非对象上调用成员函数prepare()

public function query($sql, $params = array()){
    $this->_error= false;
    if($this->_query = $this->_pdo->prepare($sql)){
        $x = 1;
        if(count ($params)){
            foreach($params as $param){
                $this->_query->bindValue($x, $param);
                $x++;
            }
        }

        if($this->_query->execute()){
            $this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ);
            $this->_count = $this->_query->rowCount();
        } else {
            $this->_error = true;
        }
    }

    return $this;
}
是什么导致它。对不起,我对PDO和OOP很新。

EDITED 我的PDO declear和__construct函数是

private $_pdo;      
private function __construct(){
    try {
        $this->_pdo = new PDO(
        'mysql:host=' . config::get('mysql/host'),//get host name
        'dbname=' . config::get('mysql/db'),//get database name
        config::get('mysql/username'), 
        config::get('mysql/password'));
    } catch (PDOException $e){
            die($e->getMessage());
        }
}

1 个答案:

答案 0 :(得分:0)

$this->_pdo = new PDO(...)之后,您的$this->_pdofalsevar_dump($this->_pdo)看到它。

相关问题