You are here

public function InsertQuery::fields in Drupal 7

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

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

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

Return value

InsertQuery The called object.

1 call to InsertQuery::fields()
InsertQuery::preExecute in includes/database/query.inc
Preprocesses and validates the query.

File

includes/database/query.inc, line 526
Non-specific Database query code. Used by all engines.

Class

InsertQuery
General class for an abstracted INSERT 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;
}