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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 메소드들

메소드 설명
__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.