function PrefetchedResult::fetch

Fetches the next row.

Parameters

\Drupal\Core\Database\Statement\FetchAs $mode: One of the cases of the FetchAs enum.

array{class?: class-string, constructor_args?: list<mixed>, column?: int, cursor_orientation?: int, cursor_offset?: int} $fetchOptions: An array of fetch options.

Return value

array|object|int|float|string|bool|null A result, formatted according to $mode, or FALSE on failure.

Overrides ResultBase::fetch

1 call to PrefetchedResult::fetch()
PrefetchedResult::fetchAllKeyed in core/lib/Drupal/Core/Database/Statement/PrefetchedResult.php
Returns the entire result set as a single associative array.

File

core/lib/Drupal/Core/Database/Statement/PrefetchedResult.php, line 70

Class

PrefetchedResult
Class for prefetched results of a data query language (DQL) statement.

Namespace

Drupal\Core\Database\Statement

Code

public function fetch(FetchAs $mode, array $fetchOptions) : array|object|int|float|string|bool|null {
  $this->currentRowIndex++;
  if (!isset($this->data[$this->currentRowIndex])) {
    $this->currentRowIndex = NULL;
    return FALSE;
  }
  $rowAssoc = $this->data[$this->currentRowIndex];
  unset($this->data[$this->currentRowIndex]);
  return $this->assocToFetchMode($rowAssoc, $mode, $fetchOptions);
}

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