我想在PHP中创建一个方法,它将动态绑定参数到PDO查询语句。不幸的是,在我的代码下面,我只能绑定1个参数,因为添加更多参数将覆盖以前的参数。不过,有没有解决这个问题的好方法?PDO绑定参数与参数
我希望有人能帮忙。谢谢!
function executeQuery($query, $critArr = null) {
$rows = array();
try {
$stmt=$this->pdo->prepare($query);
if (!empty($critArr)) {
foreach($critArr as $cKey=>$cValue) {
$stmt->bindParam($cKey, $cValue); //!!
}
}
$stmt->execute();