Query_Builder_Update クラス

(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.

table($table)

The table method sets/changes the table to update.

Static No
パラメータ
パラメータ 規定値 説明
$table string 必須 the table name
返り値 Returns the current instance.
// prepare an update statement
$query = DB::update('users');

// Set the table to update
$query->table('admins');

// UPDATE `admins` ...

value($column, $value)

The value method sets a column and value to update.

Static No
パラメータ
パラメータ 規定値 説明
$column string 必須 the column to update
$value mixed 必須 the new value
返り値 Returns the current instance.
// prepare an update statement
$query = DB::update('users');

// Set the columns
$query->value('name', 'Frank');

// UPDATE `users` SET `name` = "Frank"

set(array $pairs)

The set method sets the columns and values to update.

Static No
パラメータ
パラメータ 規定値 説明
$pairs array 必須 associative array of columns and values
返り値 Returns the current instance.
// prepare an update statement
$query = DB::update('users');

// Set the columns and vales
$query->set(array(
	'name' => 'John',
	'surname' => 'Doe',
));

// UPDATE `users` SET `name` = "John", `surname` = "Doe"

compile(\Database_Connection$db)

The compile method returns the update SQL query as a string.

Static No
パラメータ
パラメータ 規定値 説明
$db object 必須 A database connection
返り値 Returns the SQL query as a string.
// prepare an update statement
$query = DB::update('users');

// Set two values
$query->set(array(
	'name' => 'Bert',
	'surname' => 'Klaassen',
));

// Get the database connection
$connection = Database_Connection::instance();

// Get the sql query
$sql = $query->compile($connection);

reset()

The reset method resets all values of the current instance.

Static No
パラメータ None
返り値 Returns the current instance.
// prepare an update statement
$query = DB::update('users');

// Set two values
$query->set(array(
	'name' => 'Bert',
	'surname' => 'Klaassen',
));

// Reset it
$query->reset();

// Just set one
$query->value('name', 'Hank');

// Get the database connection
$connection = Database_Connection::instance();

// Get the sql query
$sql = $query->compile($connection);

// UPDATE `users` SET `name` = "Hank"

join($table, $type = null)

The join method appends tables to join.

Static No
パラメータ
パラメータ 規定値 説明
$table mixed 必須 table name or array($table, $alias)
$type mixed
true
join type (LEFT, RIGHT, INNER, etc)
返り値 Returns the current instance.
View example here

on($c1, $op, $c2)

The on method adds "ON ..." conditions for the last created JOIN statement.

Static No
パラメータ
パラメータ 規定値 説明
$c1 mixed 必須 table name or array($table, $alias)
$op string 必須 logical operator
$c2 mixed 必須 table name or array($table, $alias)
返り値 Returns the current instance.
// prepare an update statement
$query = DB::update('users');

// Join a table
$query->join('profiles');
$query->on('users.id', '=', 'profiles.user_id');

// Use a Database_Expression so the value does not get escaped.
$query->value('users.profile_type', \DB::expr('`profiles`.`type`'));

// UPDATE `users` JOIN `profiles` ON `users`.`id` = `profiles`.`user_id` SET `users`.`profile_type` = `profiles`.`type`