function Result::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

File

core/modules/mysqli/src/Driver/Database/mysqli/Result.php, line 80

Class

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

Namespace

Drupal\mysqli\Driver\Database\mysqli

Code

public function fetch(FetchAs $mode, array $fetchOptions) : array|object|int|float|string|bool|null {
  assert($this->mysqliResult instanceof \mysqli_result);
  $mysqli_row = $this->mysqliResult
    ->fetch_assoc();
  if (!$mysqli_row) {
    return FALSE;
  }
  // Stringify all non-NULL column values.
  $row = array_map(fn($value) => $value === NULL ? NULL : (string) $value, $mysqli_row);
  return $this->assocToFetchMode($row, $mode, $fetchOptions);
}

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