Interface Yiisoft\Db\Query\DataReaderInterface
| Extends | Countable, Iterator |
|---|---|
| Implemented by | Yiisoft\Db\Driver\Pdo\PdoDataReader |
This interface represents a forward-only stream of rows from a query result set.
To read the current row of data just iterate on it.
For example,
$command = $connection->createCommand('SELECT * FROM post');
$reader = $command->query();
foreach ($reader as $row) {
$rows[] = $row;
}
Note: That since DataReader is a forward-only stream, you can only traverse it once. Doing it the second time will
throw an exception.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| current() | Returns the current row or false if there is no row at the current position. | Yiisoft\Db\Query\DataReaderInterface |
| indexBy() | Sets indexBy property. |
Yiisoft\Db\Query\DataReaderInterface |
| key() | Returns the index of the current row or null if {@see indexBy} property is specified and there is no row at the current position. | Yiisoft\Db\Query\DataReaderInterface |
| resultCallback() | Sets the callback, to be called on all rows of the query result before returning them. | Yiisoft\Db\Query\DataReaderInterface |
| typecastColumns() | Sets the columns for type casting the query results. | Yiisoft\Db\Query\DataReaderInterface |
Method Details
Returns the current row or false if there is no row at the current position.
This method is required by the interface {@see \Iterator}.
| public abstract array|object|false current ( ) |
public function current(): array|object|false;
Sets indexBy property.
| public abstract Yiisoft\Db\Query\DataReaderInterface indexBy ( Closure|string|null $indexBy ) | ||
| $indexBy | Closure|string|null |
The name of the column by which the query results should be indexed by.
This can also be a The signature of the callable should be:
|
public function indexBy(Closure|string|null $indexBy): static;
Returns the index of the current row or null if {@see indexBy} property is specified and there is no row at the current position.
This method is required by the interface {@see \Iterator}.
| public abstract integer|string|null key ( ) |
public function key(): int|string|null;
Sets the callback, to be called on all rows of the query result before returning them.
For example:
function (array $rows): array {
foreach ($rows as &$row) {
$row['name'] = strtoupper($row['name']);
}
return $rows;
}
| public abstract Yiisoft\Db\Query\DataReaderInterface resultCallback ( Closure|null $resultCallback ) | ||
| $resultCallback | Closure|null | |
public function resultCallback(?Closure $resultCallback): static;
Sets the columns for type casting the query results.
Do not use this method if you want to get the raw data from the query.
| public abstract Yiisoft\Db\Query\DataReaderInterface typecastColumns ( Yiisoft\Db\Schema\Column\ColumnInterface[] $typecastColumns ) | ||
| $typecastColumns | Yiisoft\Db\Schema\Column\ColumnInterface[] | |
public function typecastColumns(array $typecastColumns): static;
Signup or Login in order to comment.