1 query.inc public InsertQuery::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: 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.

File

core/includes/database/query.inc, line 536
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;
}