Update
A class for creating SQL UPDATE statements. It extends the base Query class and inherits its WHERE clause capabilities.
Methods
addData(array $data)
Adds or replaces multiple column-value pairs in the update dataset.
Example:
use Staple\Query\Update;
$update = new Update('users');
$update->addData(['status' => 'inactive', 'last_modified' => date('Y-m-d H:i:s')]);
setDataColumn($column, $data, $literal)
Sets a specific column value. If $literal is true, it’s treated as raw SQL.
Example:
$update->setDataColumn('login_count', 'login_count + 1', true);
where($column, $operator, $value)
Adds a WHERE condition to the update query. Update requires at least one WHERE condition unless setAllowUnboundedUpdate(true) is called.
Example:
$update->where('id', '=', 123);
setAllowUnboundedUpdate(bool $allow)
Enables or disables protection against updates without a WHERE clause. Defaults to false for safety.
orderBy(array|string $order)
Sets the ORDER BY clause (supported by some databases like MySQL for single-table updates).
limit(int $limit, int $offset)
Sets the LIMIT and optionally OFFSET for the update.
build()
Builds and returns the SQL UPDATE statement.
execute()
Executes the UPDATE query and returns the number of affected rows.