function StatementBase::fetch

Fetches the next row from a result set.

Parameters

\Drupal\Core\Database\Statement\FetchAs|int|null $mode: (Optional) one of the cases of the FetchAs enum, or (deprecated) a \PDO::FETCH_* constant. If not specified, defaults to what is specified by setFetchMode().

int|null $cursor_orientation: Not implemented in all database drivers, don't use.

int|null $cursor_offset: Not implemented in all database drivers, don't use.

Return value

array|object|false A result, formatted according to $mode, or FALSE on failure.

Overrides StatementInterface::fetch

1 call to StatementBase::fetch()
StatementBase::fetchAssoc in core/lib/Drupal/Core/Database/Statement/StatementBase.php
Fetches the next row and returns it as an associative array.

File

core/lib/Drupal/Core/Database/Statement/StatementBase.php, line 248

Class

StatementBase
StatementInterface base implementation.

Namespace

Drupal\Core\Database\Statement

Code

public function fetch($mode = NULL, $cursorOrientation = NULL, $cursorOffset = NULL) {
  if (is_int($mode)) {
    @trigger_error("Passing the \$mode argument as an integer to fetch() 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);
    $mode = $this->pdoToFetchAs($mode);
  }
  assert($mode === NULL || $mode instanceof FetchAs);
  $fetchOptions = match (func_num_args()) {  0 => $this->fetchOptions,
    1 => $this->fetchOptions,
    2 => $this->fetchOptions + [
      'cursor_orientation' => $cursorOrientation,
    ],
    default => $this->fetchOptions + [
      'cursor_orientation' => $cursorOrientation,
      'cursor_offset' => $cursorOffset,
    ],
  
  };
  $row = $this->result
    ->fetch($mode ?? $this->fetchMode, $fetchOptions);
  if ($row === FALSE) {
    $this->markResultsetFetchingComplete();
    return FALSE;
  }
  $this->setResultsetCurrentRow($row);
  return $row;
}

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