PHP Class 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.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Object, implements Iterator, implements Countable
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Méthode Description
__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.

Method Details

__construct() public méthode

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() public méthode

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.
See also: 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() public méthode

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

count() public méthode

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
Résultat integer number of rows contained in the result.

current() public méthode

This method is required by the interface [[\Iterator]].
public current ( ) : mixed
Résultat mixed the current row.

getColumnCount() public méthode

Note, even there's no row in the reader, this still gives correct column number.
public getColumnCount ( ) : integer
Résultat integer the number of columns in the result set.

getIsClosed() public méthode

whether the reader is closed or not.
public getIsClosed ( ) : boolean
Résultat boolean whether the reader is closed or not.

getRowCount() public méthode

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
Résultat integer number of rows contained in the result.

key() public méthode

This method is required by the interface [[\Iterator]].
public key ( ) : integer
Résultat integer the index of the current row.

next() public méthode

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

nextResult() public méthode

This method is only useful when there are multiple result sets returned by the query. Not all DBMS support this feature.
public nextResult ( ) : boolean
Résultat boolean Returns true on success or false on failure.

read() public méthode

Advances the reader to the next row in a result set.
public read ( ) : array
Résultat array the current row, false if no more row available

readAll() public méthode

Reads the whole result set into an array.
public readAll ( ) : array
Résultat 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() public méthode

Returns a single column from the next row of a result set.
public readColumn ( integer $columnIndex ) : mixed
$columnIndex integer zero-based column index
Résultat mixed the column of the current row, false if no more rows available

readObject() public méthode

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
Résultat mixed the populated object, false if no more row of data available

rewind() public méthode

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

setFetchMode() public méthode

Set the default fetch mode for this statement
See also: http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
public setFetchMode ( integer $mode )
$mode integer fetch mode

valid() public méthode

This method is required by the interface [[\Iterator]].
public valid ( ) : boolean
Résultat boolean whether there is a row of data at current position.