我编写了一个函数,应该用数组中的值替换 ?,但我无法让它工作。
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 = ? )