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
}
ただし、実際にはそのためにORMを使用する必要があります: