I have got a function for querying my database:
public function query($sql, $params = array()) {
// reset error back to false
$this->_error = false;
// check query to prepare
if($this->_query = $this->_pdo->prepare($sql)) {
$x = 1;
if(count($params)) {
foreach($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
print_r($this->_pdo->errorInfo());
}
// check query execution
if ($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
// error
$this->_error = true;
}
}
return $this;
}
But there is something not working. The line $this->_query->bindValue($x, $param);
is not doing what it ought to do. There is no binding happening. The array with parameters thrown into the function seems fine. The $sql
statement is fine as well and is returning:
INSERT INTO responders (`username`, `password`, `salt`) VALUES (?, ?, ?)
That should be perfect for using the bind method. But after going through the foreach loop nothing has changed and the _query var is still the same. So no entry to the DB will be made at all. I also tree to use the errorInfo and got back:
Array ( [0] => 00000 [1] => [2] => )
Can anyone give me a clue what I am missing here?