PHP Класс yii\db\DataReader

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.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Object, implements Iterator, implements Countable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( Command $command, array $config = [] ) Constructor.
bindColumn ( integer | string $column, mixed &$value, integer $dataType = null ) Binds a column to a PHP variable.
close ( ) Closes the reader.
count ( ) : integer Returns the number of rows in the result set.
current ( ) : mixed Returns the current row.
getColumnCount ( ) : integer Returns the number of columns in the result set.
getIsClosed ( ) : boolean whether the reader is closed or not.
getRowCount ( ) : integer Returns the number of rows in the result set.
key ( ) : integer Returns the index of the current row.
next ( ) Moves the internal pointer to the next row.
nextResult ( ) : boolean Advances the reader to the next result when reading the results of a batch of statements.
read ( ) : array Advances the reader to the next row in a result set.
readAll ( ) : array Reads the whole result set into an array.
readColumn ( integer $columnIndex ) : mixed Returns a single column from the next row of a result set.
readObject ( string $className, array $fields ) : mixed Returns an object populated with the next row of data.
rewind ( ) Resets the iterator to the initial state.
setFetchMode ( integer $mode ) Set the default fetch mode for this statement
valid ( ) : boolean Returns whether there is a row of data at current position.

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( Command $command, array $config = [] )
$command Command the command generating the query result
$config array name-value pairs that will be used to initialize the object properties

bindColumn() публичный Метод

When rows of data are being fetched, the corresponding column value will be set in the variable. Note, the fetch mode must include PDO::FETCH_BOUND.
См. также: http://www.php.net/manual/en/function.PDOStatement-bindColumn.php
public bindColumn ( integer | string $column, mixed &$value, integer $dataType = null )
$column integer | string Number of the column (1-indexed) or name of the column in the result set. If using the column name, be aware that the name should match the case of the column, as returned by the driver.
$value mixed Name of the PHP variable to which the column will be bound.
$dataType integer Data type of the parameter

close() публичный Метод

This frees up the resources allocated for executing this SQL statement. Read attempts after this method call are unpredictable.
public close ( )

count() публичный Метод

This method is required by the Countable interface. Note, most DBMS may not give a meaningful count. In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
public count ( ) : integer
Результат integer number of rows contained in the result.

current() публичный Метод

This method is required by the interface [[\Iterator]].
public current ( ) : mixed
Результат mixed the current row.

getColumnCount() публичный Метод

Note, even there's no row in the reader, this still gives correct column number.
public getColumnCount ( ) : integer
Результат integer the number of columns in the result set.

getIsClosed() публичный Метод

whether the reader is closed or not.
public getIsClosed ( ) : boolean
Результат boolean whether the reader is closed or not.

getRowCount() публичный Метод

Note, most DBMS may not give a meaningful count. In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
public getRowCount ( ) : integer
Результат integer number of rows contained in the result.

key() публичный Метод

This method is required by the interface [[\Iterator]].
public key ( ) : integer
Результат integer the index of the current row.

next() публичный Метод

This method is required by the interface [[\Iterator]].
public next ( )

nextResult() публичный Метод

This method is only useful when there are multiple result sets returned by the query. Not all DBMS support this feature.
public nextResult ( ) : boolean
Результат boolean Returns true on success or false on failure.

read() публичный Метод

Advances the reader to the next row in a result set.
public read ( ) : array
Результат array the current row, false if no more row available

readAll() публичный Метод

Reads the whole result set into an array.
public readAll ( ) : array
Результат array the result set (each array element represents a row of data). An empty array will be returned if the result contains no row.

readColumn() публичный Метод

Returns a single column from the next row of a result set.
public readColumn ( integer $columnIndex ) : mixed
$columnIndex integer zero-based column index
Результат mixed the column of the current row, false if no more rows available

readObject() публичный Метод

Returns an object populated with the next row of data.
public readObject ( string $className, array $fields ) : mixed
$className string class name of the object to be created and populated
$fields array Elements of this array are passed to the constructor
Результат mixed the populated object, false if no more row of data available

rewind() публичный Метод

This method is required by the interface [[\Iterator]].
public rewind ( )

setFetchMode() публичный Метод

Set the default fetch mode for this statement
См. также: http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
public setFetchMode ( integer $mode )
$mode integer fetch mode

valid() публичный Метод

This method is required by the interface [[\Iterator]].
public valid ( ) : boolean
Результат boolean whether there is a row of data at current position.