public function InsertQuery_mysql::execute

public InsertQuery_mysql::execute()

Executes the insert query.

Return value

The last insert ID of the query, if one exists. If the query was given multiple sets of values to insert, the return value is undefined. If no fields are specified, this method will do nothing and return NULL. That makes it safe to use in multi-insert loops.

Overrides InsertQuery::execute

File

includes/database/mysql/query.inc, line 16
Query code for MySQL embedded database engine.

Class

InsertQuery_mysql

Code

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

  // If we're selecting from a SelectQuery, finish building the query and
  // pass it back, as any remaining options are irrelevant.
  if (empty($this->fromQuery)) {
    $max_placeholder = 0;
    $values = array();
    foreach ($this->insertValues as $insert_values) {
      foreach ($insert_values as $value) {
        $values[':db_insert_placeholder_' . $max_placeholder++] = $value;
      }
    }
  }
  else {
    $values = $this->fromQuery->getArguments();
  }

  $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/includes!database!mysql!query.inc/function/InsertQuery_mysql::execute/7.x