class PdoResult

Class for PDO-provided results of a data query language (DQL) statement.

Hierarchy

Expanded class hierarchy of PdoResult

1 file declares its use of PdoResult
StatementWrapperIterator.php in core/lib/Drupal/Core/Database/StatementWrapperIterator.php

File

core/lib/Drupal/Core/Database/Statement/PdoResult.php, line 10

Namespace

Drupal\Core\Database\Statement
View source
class PdoResult extends ResultBase {
  use PdoTrait;
  
  /**
   * Constructor.
   *
   * @param \Drupal\Core\Database\Statement\FetchAs $fetchMode
   *   The fetch mode.
   * @param array{class: class-string, constructor_args: list<mixed>, column: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions
   *   The fetch options.
   * @param \PDOStatement $clientStatement
   *   The PDO Statement object. PDO does not provide a separate object for
   *   results, se we need to fetch data from the Statement.
   */
  public function __construct(FetchAs $fetchMode, array $fetchOptions, protected readonly \PDOStatement $clientStatement) {
    parent::__construct($fetchMode, $fetchOptions);
  }
  
  /**
   * Returns the client-level database PDO statement object.
   *
   * This method should normally be used only within database driver code.
   *
   * @return \PDOStatement
   *   The client-level database PDO statement.
   */
  public function getClientStatement() : \PDOStatement {
    return $this->clientStatement;
  }
  
  /**
   * {@inheritdoc}
   */
  public function rowCount() : ?int {
    return $this->clientRowCount();
  }
  
  /**
   * {@inheritdoc}
   */
  public function setFetchMode(FetchAs $mode, array $fetchOptions) : bool {
    return match ($mode) {  FetchAs::ClassObject => $this->clientSetFetchMode($mode, $fetchOptions['class'], $fetchOptions['constructor_args'] ?? NULL),
      FetchAs::Column => $this->clientSetFetchMode($mode, $fetchOptions['column']),
      default => $this->clientSetFetchMode($mode),
    
    };
  }
  
  /**
   * {@inheritdoc}
   */
  public function fetch(FetchAs $mode, array $fetchOptions) : array|object|int|float|string|bool|null {
    if (!empty($fetchOptions)) {
      $this->setFetchMode($mode, $fetchOptions);
    }
    if (isset($fetchOptions['cursor_orientation'])) {
      if (isset($fetchOptions['cursor_offset'])) {
        return $this->clientFetch($mode, $fetchOptions['cursor_orientation'], $fetchOptions['cursor_offset']);
      }
      return $this->clientFetch($mode, $fetchOptions['cursor_orientation']);
    }
    return $this->clientFetch($mode);
  }
  
  /**
   * {@inheritdoc}
   */
  public function fetchAll(FetchAs $mode, array $fetchOptions) : array {
    return $this->clientFetchAll($mode, $fetchOptions['column'] ?? $fetchOptions['class'] ?? NULL, $fetchOptions['constructor_args'] ?? NULL);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
FetchModeTrait::$fetchModeLiterals protected property Map FETCH_* modes to their literal for inclusion in messages.
FetchModeTrait::$supportedFetchModes protected property The fetch modes supported.
FetchModeTrait::assocToClass protected function Converts a row of data in FETCH_ASSOC format to FETCH_CLASS.
FetchModeTrait::assocToColumn protected function Converts a row of data in FETCH_ASSOC format to FETCH_COLUMN.
FetchModeTrait::assocToFetchMode protected function Converts a row of data in associative format to a specified format.
FetchModeTrait::assocToNum protected function Converts a row of data in FETCH_ASSOC format to FETCH_NUM.
FetchModeTrait::assocToObj protected function Converts a row of data in FETCH_ASSOC format to FETCH_OBJ.
PdoResult::fetch public function Fetches the next row. Overrides ResultBase::fetch
PdoResult::fetchAll public function Returns an array containing all of the result set rows. Overrides ResultBase::fetchAll
PdoResult::getClientStatement public function Returns the client-level database PDO statement object. Overrides PdoTrait::getClientStatement
PdoResult::rowCount public function Returns the number of rows matched by the last SQL statement. Overrides ResultBase::rowCount
PdoResult::setFetchMode public function Sets the default fetch mode for this result set. Overrides ResultBase::setFetchMode
PdoResult::__construct public function Constructor. Overrides ResultBase::__construct
PdoTrait::clientExecute protected function Executes the prepared PDO statement.
PdoTrait::clientFetch protected function Fetches the next row from the PDO statement.
PdoTrait::clientFetchAll protected function Returns an array containing all of the result set rows.
PdoTrait::clientFetchColumn protected function Returns a single column from the next row of a result set.
PdoTrait::clientFetchObject protected function Fetches the next row and returns it as an object.
PdoTrait::clientQueryString protected function Returns the query string used to prepare the statement.
PdoTrait::clientRowCount protected function Returns the number of rows affected by the last SQL statement.
PdoTrait::clientSetFetchMode protected function Sets the default fetch mode for the PDO statement.
PdoTrait::fetchAsToPdo protected function Converts a FetchAs mode to a \PDO::FETCH_* constant value.
PdoTrait::pdoToFetchAs protected function Converts a \PDO::FETCH_* constant value to a FetchAs mode.
ResultBase::fetchAllAssoc public function Returns the result set as an associative array keyed by the given column.
ResultBase::fetchAllKeyed public function Returns the entire result set as a single associative array. 1

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