W3cubDocs

/Drupal 8

public function InsertTrait::fields

public InsertTrait::fields(array $fields, array $values = array())

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.

Parameters

array $fields: An array of fields on which to insert. This array may be indexed or associative. If indexed, the array is taken to be the list of fields. If associative, the keys of the array are taken to be the fields and the values are taken to be corresponding values to insert. If a $values argument is provided, $fields must be indexed.

array $values: (optional) An array of fields to insert into the database. The values must be specified in the same order as the $fields array.

Return value

$this The called object.

File

core/lib/Drupal/Core/Database/Query/InsertTrait.php, line 70

Class

InsertTrait
Provides common functionality for INSERT and UPSERT queries.

Namespace

Drupal\Core\Database\Query

Code

public function fields(array $fields, array $values = array()) {
  if (empty($this->insertFields)) {
    if (empty($values)) {
      if (!is_numeric(key($fields))) {
        $values = array_values($fields);
        $fields = array_keys($fields);
      }
    }
    $this->insertFields = $fields;
    if (!empty($values)) {
      $this->insertValues[] = $values;
    }
  }

  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!InsertTrait.php/function/InsertTrait::fields/8.1.x