没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\db\DataReader

继承yii\db\DataReader » yii\base\BaseObject
实现Countable, Iterator, yii\base\Configurable
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/db/DataReader.php

DataReader represents a forward-only stream of rows from a query result set.

To read the current row of data, call read(). The method readAll() returns all the rows in a single array. Rows of data can also be read by iterating through the reader. For example,

$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.

公共属性

隐藏继承的属性

属性类型描述被定义在
$columnCount integer The number of columns in the result set. yii\db\DataReader
$fetchMode integer Fetch mode yii\db\DataReader
$isClosed boolean Whether the reader is closed or not. yii\db\DataReader
$rowCount integer Number of rows contained in the result. yii\db\DataReader

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\db\DataReader
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
bindColumn() Binds a column to a PHP variable. yii\db\DataReader
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
close() Closes the reader. yii\db\DataReader
count() Returns the number of rows in the result set. yii\db\DataReader
current() Returns the current row. yii\db\DataReader
getColumnCount() Returns the number of columns in the result set. yii\db\DataReader
getIsClosed() Whether the reader is closed or not. yii\db\DataReader
getRowCount() Returns the number of rows in the result set. yii\db\DataReader
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
key() Returns the index of the current row. yii\db\DataReader
next() Moves the internal pointer to the next row. yii\db\DataReader
nextResult() Advances the reader to the next result when reading the results of a batch of statements. yii\db\DataReader
read() Advances the reader to the next row in a result set. yii\db\DataReader
readAll() Reads the whole result set into an array. yii\db\DataReader
readColumn() Returns a single column from the next row of a result set. yii\db\DataReader
readObject() Returns an object populated with the next row of data. yii\db\DataReader
rewind() Resets the iterator to the initial state. yii\db\DataReader
setFetchMode() Set the default fetch mode for this statement. yii\db\DataReader
valid() Returns whether there is a row of data at current position. yii\db\DataReader

属性详情

$columnCount 公共 只读 属性

The number of columns in the result set.

$fetchMode 公共 只写 属性

Fetch mode

public void setFetchMode ( $mode )
$isClosed 公共 只读 属性

Whether the reader is closed or not.

public boolean getIsClosed ( )
$rowCount 公共 只读 属性

Number of rows contained in the result.

public integer getRowCount ( )

方法详情

__construct() 公共 方法

Constructor.

public void __construct(yii\db\Command $command, $config = [])
$command yii\db\Command

The command generating the query result

$config array

Name-value pairs that will be used to initialize the object properties

bindColumn() 公共 方法

Binds a column to a PHP variable.

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 void bindColumn($column, &$value, $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() 公共 方法

Closes the reader.

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

public void close()
count() 公共 方法

Returns the number of rows in the result set.

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 integer count()
return integer

Number of rows contained in the result.

current() 公共 方法

Returns the current row.

This method is required by the interface Iterator.

public mixed current()
return mixed

The current row.

getColumnCount() 公共 方法

Returns the number of columns in the result set.

Note, even there's no row in the reader, this still gives correct column number.

public integer getColumnCount()
return integer

The number of columns in the result set.

getIsClosed() 公共 方法

Whether the reader is closed or not.

public boolean getIsClosed()
return boolean

Whether the reader is closed or not.

getRowCount() 公共 方法

Returns the number of rows in the result set.

Note, most DBMS may not give a meaningful count. In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.

public integer getRowCount()
return integer

Number of rows contained in the result.

key() 公共 方法

Returns the index of the current row.

This method is required by the interface Iterator.

public integer key()
return integer

The index of the current row.

next() 公共 方法

Moves the internal pointer to the next row.

This method is required by the interface Iterator.

public void next()
nextResult() 公共 方法

Advances the reader to the next result when reading the results of a batch of statements.

This method is only useful when there are multiple result sets returned by the query. Not all DBMS support this feature.

public boolean nextResult()
return boolean

Returns true on success or false on failure.

read() 公共 方法

Advances the reader to the next row in a result set.

public array read()
return array

The current row, false if no more row available

readAll() 公共 方法

Reads the whole result set into an array.

public array readAll()
return 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 mixed readColumn($columnIndex)
$columnIndex integer

Zero-based column index

return 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 mixed readObject($className, $fields)
$className string

Class name of the object to be created and populated

$fields array

Elements of this array are passed to the constructor

return mixed

The populated object, false if no more row of data available

rewind() 公共 方法

Resets the iterator to the initial state.

This method is required by the interface Iterator.

public void rewind()
throws yii\base\InvalidCallException

if this method is invoked twice

setFetchMode() 公共 方法

Set the default fetch mode for this statement.

参见 http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php.

public void setFetchMode($mode)
$mode integer

Fetch mode

valid() 公共 方法

Returns whether there is a row of data at current position.

This method is required by the interface Iterator.

public boolean valid()
return boolean

Whether there is a row of data at current position.