Я думаю, это то, что вы ищете:
public function delete($table, $where = [])
{
$_where = array_reduce(array_keys($where), function($prev,$key){
return $prev . ' AND ' . $key . '=:' . $key;
},'1=1');
$sql = sprintf(
'delete from %s where %s',
$table,
$_where
);
try {
$statement = $this->pdo->prepare($sql);
$statement->execute($where);
} catch (\Exception $e) {
//
}
}
public function update($table, $values, $where=[]){
$_where = array_reduce(array_keys($where), function($prev, $key){
return sprintf("%s AND %s=:%s", $prev, $key, $key);
},'1=1');
$_set = array_reduce(array_keys($values), function($prev, $key){
return sprintf("%s,%s=:%s", $prev, $key, $key);
}, '');
$sql = sprintf(
'update %s set %s where %s',
$table,
$_set,
$_where
);
try {
$statement = $this->pdo->prepare($sql);
$statement->execute($where);
} catch (\Exception $e) {
//
}
}