Skip to content

Updating records ​

Updating existing records is done by using the update() method. This method accepts a single argument that represents a key => value mapped array where the key is the name of the column and the value is the actual value that will be used to update the record.

Basic usage ​

php
$query_builder = new QueryBuilder();

$update = $query_builder->update([
    'column1' => 'value1',
    'column2' => 'value2',
    // ... more columns and values
]);

Then, you'd specify the table to update using the into() method:

php
$result = $update->into('table_name');

This into() method not only specifies the table but also executes the update immediately, returning the number of affected rows or false on error.

Specifying conditions ​

You can specify conditions using the where() method.

php
$result = $update->into('table_name')->where('id', 1);