我已经写了一个函数,应该用数组中的值替换?的值,但是我无法让它正常工作。PDO bindParam错误
public function exec($sql, Array $params = array()) {
if($query = $this->db->prepare($sql)) {
$x = 1;
if(count($params)) {
foreach($params as $param) {
$query->bindParam($x, $param);
$x++;
}
}
}
$query->execute();
print_r($query);
查询:
$mysql->exec("SELECT * FROM test where id = ?", array(0));
输出:
PDOStatement Object ([queryString] => SELECT * FROM test where id = ?)
你什么错误? – Vallentin
没有错误,但?没有被取代。 – ethan476
'print_r($ query);'不会工作,因为绑定查询不存在于php中,因为查询/参数被单独发送到mysql。见http://stackoverflow.com/questions/210564或http://stackoverflow.com/questions/1786322或http://stackoverflow.com/questions/11122573或http://stackoverflow.com/questions/530627-it/530705#530705。你可以使用['print_r($ query-> debugDumpParams());'](http://php.net/manual/en/pdostatement.debugdumpparams.php) – Sean