table($table); } } public function table(string $table): Database\Query\Update { return $this->setTable($table); } public function set(array|string $value_pairs): Database\Query\Update { return $this->setValues($value_pairs); } public function where(array|string $conditions): Database\Query\Update { return $this->setConditions($conditions); } protected array|string $values; public function getValues(): array { return $this->values; } public function addValue(string|array $values): Database\Query\Update { if (is_string($values)) { $this->values []= $values; return $this; } $column = $values['column'] ?? $values[0]; $value = $values['value'] ?? $values[1]; if (!is_numeric($value)) { $value = "'{$value}'"; } $this->values []= "`{$column}` = {$value}"; return $this; } public function setValues(array|string $values): Database\Query\Update { if (is_string($values)) { $this->addValue($values); return $this; } foreach ($values as $value) { $this->addValue($value); } return $this; } protected function getValuesString(): string { if (!isset($this->values)) { return ''; } $values = (is_array($this->getValues())) ? implode(', ', $this->getValues()) : $this->getValues(); return " SET {$values}"; } public function build(): string { return implode('', [ "UPDATE {$this->getTable()}", $this->getValuesString(), $this->getConditionsString() ]); } }