public function update($table, $columnValues, $conditions, $bind = [])
{
$escapedTable = "`{$table}`";
if (count($columnValues) === 0) {
throw new DbException('Unable to update :table table without data', ['table' => $table]);
}
if (is_string($conditions)) {
$conditions = [$conditions];
}
$wheres = [];
/** @noinspection ForeachSourceInspection */
foreach ($conditions as $k => $v) {
if (is_int($k)) {
$wheres[] = Text::contains($v, ' or ', true) ? "({$v})" : $v;
} else {
$wheres[] = "`{$k}`=:{$k}";
$bind[$k] = $v;
}
}
$setColumns = [];
foreach ($columnValues as $k => $v) {
if (is_int($k)) {
$setColumns[] = $v;
} else {
$setColumns[] = "`{$k}`=:{$k}";
$bind[$k] = $v;
}
}
$updateColumns = implode(',', $setColumns);
$updateSql = "UPDATE {$escapedTable} SET {$updateColumns} WHERE " . implode(' AND ', $wheres);
return $this->execute($updateSql, $bind);
}