public function update($tableName, $values, $conditions = array()) {
if (empty($values)) {
throw new Exception('Nothing to update');
}
$valueStrings = array();
foreach ($values as $name => $value) {
$valueStrings[] = $name . ' = :' . $name;
}
$conditionStrings = array();
foreach ($conditions as $column => $value) {
$conditionString = $column;
$conditionString .= is_array($value)
? ('IN ("' . implode('","', $value) . '")')
: (' = "' . $value . '"')
;
$conditionStrings[] = $conditionString;
}
$sql = 'UPDATE ' . $tableName
. ' SET ' . implode(', ', $valueStrings)
. ' WHERE ' . implode(' AND ', $conditionStrings)
;
// execute query
}
Pero en realidad deberías usar un ORM para eso:
Doctrine 2:Actualizar consulta con el generador de consultas