To read the current row of data, call DataReader::read. The method DataReader::readAll
returns all the rows in a single array. Rows of data can also be read by
iterating through the reader. For example,
php
$command = $connection->createCommand('SELECT * FROM post');
$reader = $command->query();
while ($row = $reader->read()) {
$rows[] = $row;
}
equivalent to:
foreach ($reader as $row) {
$rows[] = $row;
}
equivalent to:
$rows = $reader->readAll();
Note that since DataReader is a forward-only stream, you can only traverse it once.
Doing it the second time will throw an exception.
It is possible to use a specific mode of data fetching by setting
[[fetchMode]]. See the PHP manual
for more details about possible fetch mode.