我有一个查询我的数据库的功能:
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;
}
但是有些东西不起作用。这条线$this->_query->bindValue($x, $param);
没有做它应该做的事情。没有发生绑定。将参数放入函数的数组似乎很好。该$sql
声明也很好,并且正在返回:
INSERT INTO responders (`username`, `password`, `salt`) VALUES (?, ?, ?)
这对于使用 bind 方法应该是完美的。但是经过 foreach 循环之后,什么都没有改变,_query var 仍然是一样的。所以根本不会进入数据库。我也树使用errorInfo并返回:
Array ( [0] => 00000 [1] => [2] => )
谁能给我一个线索我在这里想念什么?