Query_Builder_Insert クラス

(extends Query_Builder_Where)

The Query_Builder_Insert class handles all the insert 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 insert into.

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

// Update the table to insert into
$query->table('admins');

// INSERT INTO `admins` ...

columns(array $columns)

The columns method sets/changes the columns to insert.

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

// Set the columns
$query->columns(array(
	'name',
	'surname',
	'email')
);

// INSERT INTO `users` (`name`, `surname`, `email`)

values(array $values)

The values method appends the values to insert.

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

// Set the columns
$query->columns(array(
	'name',
	'surname',
	'email',
));

// Set the values

$query->values(array(
	'John',
	'Doe',
	'john@doe.com',
));

// INSERT INTO `users` (`name`, `surname`, `email`) VALUES ("John", "Doe", "john@doe.com")

set(array $pairs)

The set method sets the columns and appends the values to insert.

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

// Set the columns and vales
$query->set(array(
	'name' => 'John',
	'surname' => 'Doe',
	'email' => 'john@doe.com',
));

// INSERT INTO `users` (`name`, `surname`, `email`) VALUES ("John", "Doe", "john@doe.com")

compile(\Database_Connection$db)

The limit method returns the insert SQL query as a string.

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

// Set the limit and offset
$query->limit(10);
$query->offset(5);

// 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 insert statement
$query = DB::insert('users');

// Set some values
$query->set(array(
	'name' => 'John',
	'surname' => 'Doe',
));

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

// Set the new values
$query->table('admins')->set(array(
	'name' => 'Mark',
	'surname' => 'Handriks'
));

// The SQL query will now be:
// INSERT INTO `admins` (`name`, `surname`) VALUES ("Mark", "Hendriks")