InsertQuery::fields

public function InsertQuery::fields

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

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

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;
}

© 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/includes!database!query.inc/function/InsertQuery::fields/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部