Versions
Look up a class, method, property or event

CDbDataReader

Package system.db
Inheritance class CDbDataReader » CComponent
Implements Iterator, Traversable
Since 1.0
Version $Id: CDbDataReader.php 433 2008-12-30 22:59:17Z qiang.xue $
CDbDataReader 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.

One can also retrieve the rows of data in CDbDataReader by using foreach:
foreach($reader as $row)
    // $row represents a row of data
Since CDbDataReader is a forward-only stream, you can only traverse it once.

It is possible to use a specific mode of data fetching by setting FetchMode. See http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php for more details.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
columnCount int the number of columns in the result set. CDbDataReader
isClosed boolean whether the reader is closed or not. CDbDataReader
rowCount int number of rows contained in the result. CDbDataReader

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CDbDataReader
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
bindColumn() Binds a column to a PHP variable. CDbDataReader
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
close() Closes the reader. CDbDataReader
current() Returns the current row. CDbDataReader
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getColumnCount() CDbDataReader
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIsClosed() CDbDataReader
getRowCount() CDbDataReader
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
key() Returns the index of the current row. CDbDataReader
next() Moves the internal pointer to the next row. CDbDataReader
nextResult() Advances the reader to the next result when reading the results of a batch of statements. CDbDataReader
raiseEvent() Raises an event. CComponent
read() Advances the reader to the next row in a result set. CDbDataReader
readAll() Reads the whole result set into an array. CDbDataReader
readColumn() Returns a single column from the next row of a result set. CDbDataReader
readObject() Returns an object populated with the next row of data. CDbDataReader
rewind() Resets the iterator to the initial state. CDbDataReader
setFetchMode() CDbDataReader
valid() Returns whether there is a row of data at current position. CDbDataReader

Property Details

columnCount property read-only
public int getColumnCount()

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

isClosed property read-only
public boolean getIsClosed()

whether the reader is closed or not.

rowCount property read-only
public int getRowCount()

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

Method Details

__construct() method
public void __construct(CDbCommand $command)
$command CDbCommand the command generating the query result

Constructor.

bindColumn() method
public void bindColumn(mixed $column, mixed $value, int $dataType=NULL)
$column mixed 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 int Data type of the parameter

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.

close() method
public void close()

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

current() method
public mixed current()
{return} mixed the current row.

Returns the current row. This method is required by the interface Iterator.

getColumnCount() method
public int getColumnCount()
{return} int the number of columns in the result set. Note, even there's no row in the reader, this still gives correct column number.

getIsClosed() method
public boolean getIsClosed()
{return} boolean whether the reader is closed or not.

getRowCount() method
public int getRowCount()
{return} int number of rows contained in the result. Note, most DBMS may not give a meaningful count. In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.

key() method
public integer key()
{return} integer the index of the current row.

Returns the index of the current row. This method is required by the interface Iterator.

next() method
public void next()

Moves the internal pointer to the next row. This method is required by the interface Iterator.

nextResult() method
public void 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.

read() method
public array|false read()
{return} array|false the current row, false if no more row available

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

readAll() method
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.

Reads the whole result set into an array.

readColumn() method
public mixed|false readColumn(int $columnIndex)
$columnIndex int zero-based column index
{return} mixed|false the column of the current row, false if no more row available

Returns a single column from the next row of a result set.

readObject() method
public mixed|false readObject(string $className, array $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|false the populated object, false if no more row of data available

Returns an object populated with the next row of data.

rewind() method
public void rewind()

Resets the iterator to the initial state. This method is required by the interface Iterator.

setFetchMode() method
public void setFetchMode($mode)
$mode

valid() method
public boolean valid()
{return} boolean whether there is a row of data at current position.

Returns whether there is a row of data at current position. This method is required by the interface Iterator.

Be the first person to leave a comment

Please to leave your comment.