This code get an error: Fatal error: Call to a member function prepare() on a non-object in D:\ProgramFile\Xampp\htdocs\site\shop\class\DB.php on line 32
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;
}
what can causing it. Sorry I'm very new to PDO and OOP.
EDITED
my PDO declear and __construct function is
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());
}
}
No comments:
Post a Comment