(extends Query_Builder_Where)
The Query_Builder_Update class handles all the update operations for the query building process. It extends the
Query_Builder_Where class, so all the methods are inherited.
The table method sets/changes the table to update.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$table |
string |
required |
the table name |
|
Returns |
Returns the current instance. |
Example |
$query = DB::update('users');
$query->table('admins');
|
The value method sets a column and value to update.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$column |
string |
required |
the column to update |
$value |
mixed |
required |
the new value |
|
Returns |
Returns the current instance. |
Example |
$query = DB::update('users');
$query->value('name', 'Frank');
|
The set method sets the columns and values to update.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$pairs |
array |
required |
associative array of columns and values |
|
Returns |
Returns the current instance. |
Example |
$query = DB::update('users');
$query->set(array(
'name' => 'John',
'surname' => 'Doe',
));
|
The compile method returns the update SQL query as a string.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$db |
object |
required |
A database connection |
|
Returns |
Returns the SQL query as a string. |
Example |
$query = DB::update('users');
$query->set(array(
'name' => 'Bert',
'surname' => 'Klaassen',
));
$connection = Database_Connection::instance();
$sql = $query->compile($connection);
|
The reset method resets all values of the current instance.
Static |
No |
Parameters |
None
|
Returns |
Returns the current instance. |
Example |
$query = DB::update('users');
$query->set(array(
'name' => 'Bert',
'surname' => 'Klaassen',
));
$query->reset();
$query->value('name', 'Hank');
$connection = Database_Connection::instance();
$sql = $query->compile($connection);
|
The join method appends tables to join.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$table |
mixed |
required |
table name or array($table, $alias) |
$type |
mixed |
true
|
join type (LEFT, RIGHT, INNER, etc) |
|
Returns |
Returns the current instance. |
Example |
View example here
|
The on method adds "ON ..." conditions for the last created JOIN statement.
Static |
No |
Parameters |
Param |
Type |
Default |
Description |
$c1 |
mixed |
required |
table name or array($table, $alias) |
$op |
string |
required |
logical operator |
$c2 |
mixed |
required |
table name or array($table, $alias) |
|
Returns |
Returns the current instance. |
Example |
$query = DB::update('users');
$query->join('profiles');
$query->on('users.id', '=', 'profiles.user_id');
$query->value('users.profile_type', \DB::expr('`profiles`.`type`'));
|