function StatementPrefetchIterator::fetch
Same name in other branches
- 10 core/lib/Drupal/Core/Database/StatementPrefetchIterator.php \Drupal\Core\Database\StatementPrefetchIterator::fetch()
Overrides StatementInterface::fetch
7 calls to StatementPrefetchIterator::fetch()
- StatementPrefetchIterator::fetchAll in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Returns an array containing all of the result set rows.
- StatementPrefetchIterator::fetchAllAssoc in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Returns the result set as an associative array keyed by the given field.
- StatementPrefetchIterator::fetchAllKeyed in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Returns the entire result set as a single associative array.
- StatementPrefetchIterator::fetchAssoc in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Fetches the next row and returns it as an associative array.
- StatementPrefetchIterator::fetchCol in core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php - Returns an entire single column of a result set as an indexed array.
File
-
core/
lib/ Drupal/ Core/ Database/ StatementPrefetchIterator.php, line 230
Class
- StatementPrefetchIterator
- An implementation of StatementInterface that prefetches all data.
Namespace
Drupal\Core\DatabaseCode
public function fetch($fetch_style = NULL, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = NULL) {
$currentKey = $this->getResultsetCurrentRowIndex();
// We can remove the current record from the prefetched data, before
// moving to the next record.
unset($this->data[$currentKey]);
$currentKey++;
if (!isset($this->data[$currentKey])) {
$this->markResultsetFetchingComplete();
return FALSE;
}
// Now, format the next prefetched record according to the required fetch
// style.
$rowAssoc = $this->data[$currentKey];
$mode = $fetch_style ?? $this->defaultFetchStyle;
$row = match ($mode) { \PDO::FETCH_ASSOC => $rowAssoc,
\PDO::FETCH_CLASS, \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE => $this->assocToClass($rowAssoc, $this->fetchOptions['class'], $this->fetchOptions['constructor_args']),
\PDO::FETCH_COLUMN => $this->assocToColumn($rowAssoc, $this->columnNames, $this->fetchOptions['column']),
\PDO::FETCH_NUM => $this->assocToNum($rowAssoc),
\PDO::FETCH_OBJ => $this->assocToObj($rowAssoc),
default => throw new DatabaseExceptionWrapper('Fetch mode ' . ($this->fetchModeLiterals[$mode] ?? $mode) . ' is not supported. Use supported modes only.'),
};
$this->setResultsetCurrentRow($row);
return $row;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.