$query = $connection
->update()
->table('accounts')
->values(['name' => 'Account 3'])
->where('name', '=', 'Account 1');
$statement = $connection->query($query);
You can get the number of affected rows:
$rowCount = $statement->getRowCount();
The table can be given an alias:
$query->table('accounts', 'a');
This clause is shared by multiple queries (SELECT, UPDATE, DELETE).
The following section of the documentation explains how to use the JOIN clause.
This clause is shared by multiple queries (SELECT, UPDATE, DELETE).
The following section of the documentation explains how to use the WHERE clause.
Usage:
use Foundry\Parameter;
$query = $connection
->update()
->table('accounts')
->values(['name' => new Parameter])
->where('name', '=', new Parameter);
$statement = $connection->query($query, ['Account 3', 'Account 1']);
Usage:
use Foundry\Parameter;
$query = $connection
->update()
->table('accounts')
->values(['name' => new Parameter('new')])
->where('name', '=', new Parameter('old'));
$statement = $connection->query($query, [':new' => 'Account 3', ':old' => 'Account 1']);
All clauses are additive. For example, adding a join to the query will not remove previously declared joins.
To reset a part of the query, you can use the reset
method:
public function reset($part = null);
Usage:
use Foundry\Builder\Statement\Update;
$query->reset(Update::PART_JOIN);
To completely reset the query:
$query->reset();
The reset
method is also provided by the other statements (select, insert, delete).