public function Upsert::execute

public Upsert::execute()

Runs the query against the database.

Return value

\Drupal\Core\Database\StatementInterface|null A prepared statement, or NULL if the query is not valid.

Overrides Query::execute

File

core/lib/Drupal/Core/Database/Query/Upsert.php, line 93

Class

Upsert
General class for an abstracted "Upsert" (UPDATE or INSERT) query operation.

Namespace

Drupal\Core\Database\Query

Code

public function execute() {
  if (!$this->preExecute()) {
    return NULL;
  }

  $max_placeholder = 0;
  $values = array();
  foreach ($this->insertValues as $insert_values) {
    foreach ($insert_values as $value) {
      $values[':db_insert_placeholder_' . $max_placeholder++] = $value;
    }
  }

  $last_insert_id = $this->connection->query((string) $this, $values, $this->queryOptions);

  // Re-initialize the values array so that we can re-use this query.
  $this->insertValues = array();

  return $last_insert_id;
}

© 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!Upsert.php/function/Upsert::execute/8.1.x