function Statement::execute

Same name in this branch
  1. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Statement.php \Drupal\sqlite\Driver\Database\sqlite\Statement::execute()
Same name and namespace in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Statement.php \Drupal\sqlite\Driver\Database\sqlite\Statement::execute()
  2. 9 core/lib/Drupal/Core/Database/Statement.php \Drupal\Core\Database\Statement::execute()
  3. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Statement.php \Drupal\Core\Database\Driver\sqlite\Statement::execute()
  4. 8.9.x core/lib/Drupal/Core/Database/Statement.php \Drupal\Core\Database\Statement::execute()
  5. 10 core/modules/sqlite/src/Driver/Database/sqlite/Statement.php \Drupal\sqlite\Driver\Database\sqlite\Statement::execute()

Overrides StatementBase::execute

File

core/modules/mysqli/src/Driver/Database/mysqli/Statement.php, line 71

Class

Statement
MySQLi implementation of \Drupal\Core\Database\Query\StatementInterface.

Namespace

Drupal\mysqli\Driver\Database\mysqli

Code

public function execute($args = [], $options = []) {
  if (isset($options['fetch'])) {
    if (is_string($options['fetch'])) {
      $this->setFetchMode(FetchAs::ClassObject, $options['fetch']);
    }
    else {
      if (is_int($options['fetch'])) {
        @trigger_error("Passing the 'fetch' key as an integer to \$options in execute() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \\Drupal\\Core\\Database\\Statement\\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
      }
      $this->setFetchMode($options['fetch']);
    }
  }
  $startEvent = $this->dispatchStatementExecutionStartEvent($args ?? []);
  try {
    // Prepare the lower-level statement if it's not been prepared already.
    if (!$this->hasClientStatement()) {
      // Replace named placeholders with positional ones if needed.
      $this->paramsPositions = array_flip(array_keys($args));
      $converter = new NamedPlaceholderConverter();
      $converter->parse($this->queryString, $args);
      [
        $convertedQueryString,
        $args,
      ] = [
        $converter->getConvertedSQL(),
        $converter->getConvertedParameters(),
      ];
      $this->clientStatement = $this->clientConnection
        ->prepare($convertedQueryString);
    }
    else {
      // Transform the $args to positional.
      $tmp = [];
      foreach ($this->paramsPositions as $param => $pos) {
        $tmp[$pos] = $args[$param];
      }
      $args = $tmp;
    }
    // In mysqli, the results of the statement execution are returned in a
    // different object than the statement itself.
    $return = $this->getClientStatement()
      ->execute($args);
    $this->result = new Result($this->fetchMode, $this->fetchOptions, $this->getClientStatement()
      ->get_result(), $this->clientConnection);
    $this->markResultsetIterable($return);
  } catch (\Exception $e) {
    $this->dispatchStatementExecutionFailureEvent($startEvent, $e);
    throw $e;
  }
  $this->dispatchStatementExecutionEndEvent($startEvent);
  return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.