InsertTrait
trait InsertTrait (View source)
Provides common functionality for INSERT and UPSERT queries.
Properties
| protected string | $table | The table on which to insert. |
|
| protected array | $insertFields | An array of fields on which to insert. |
|
| protected array | $defaultFields | An array of fields that should be set to their database-defined defaults. |
|
| protected array | $insertValues | A nested array of values to insert. |
Methods
Adds a set of field->value pairs to be inserted.
Adds another set of values to the query to be inserted.
Specifies fields for which the database defaults should be used.
Returns the query placeholders for values that will be inserted.
{@inheritdoc}
Details
$this
fields(array $fields, array $values = [])
Adds a set of field->value pairs to be inserted.
This method may only be called once. Calling it a second time will be ignored. To queue up multiple sets of values to be inserted at once, use the values() method.
$this
values(array $values)
Adds another set of values to the query to be inserted.
If $values is a numeric-keyed array, it will be assumed to be in the same order as the original fields() call. If it is associative, it may be in any order as long as the keys of the array match the names of the fields.
$this
useDefaults(array $fields)
Specifies fields for which the database defaults should be used.
If you want to force a given field to use the database-defined default, not NULL or undefined, use this method to instruct the database to use default values explicitly. In most cases this will not be necessary unless you are inserting a row that is all default values, as you cannot specify no values in an INSERT query.
Specifying a field both in fields() and in useDefaults() is an error and will not execute.
protected array
getInsertPlaceholderFragment(array $nested_insert_values, array $default_fields)
Returns the query placeholders for values that will be inserted.
count()
{@inheritdoc}