I have, in a db.php file, the following code:
public function query($sql, $params = array()){
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)){
$x = 1;
if(count($params)){
foreach($params AS $pa){
$this->_query->bindValue($x, $pa);
$x++;
}
}
#MASSIVE ERROR
#correctthis
if($this->_query->execute()){
echo 'success';
$this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_query = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
public function error(){
return $this->_error;
}
My problem is that $this->_query->execute()
always is false, which means $_error is always being set to true. I can't get it to work, even though there doesn't seem to be anything wrong with it.
The script enters the prepare (I tested by echoing), which means it prepared successfully. It also enters the foreach loop so the values must be getting bound. But it just can't seem to execute. Why?
Edit:
I use DB::getInstance()->query("SELECT email FROM user_credentials WHERE user_id = ?", array(1))
to call the query, and this is what getInstance looks like:
public static function getInstance(){
if(!isset(self::$_instance)){
self::$_instance = new DB();
}
return self::$_instance;
}