CDbDataReader represents a forward-only stream of rows from a query result
set.
To read the current row of data, call CDbDataReader::read()
. The method CDbDataReader::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 setFetchMode FetchMode. See http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
for more details.
Methods summary
public
|
|
public
|
#
bindColumn( mixed $column, mixed & $value, integer $dataType = null )
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.
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.
Parameters
- $column
mixed $column 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 $value Name of the PHP variable to which the column will be bound.
- $dataType
integer $dataType Data type of the parameter
See
|
public
|
#
setFetchMode( mixed $mode )
Set the default fetch mode for this statement
Set the default fetch mode for this statement
Parameters
- $mode
mixed $mode fetch mode
See
|
public
array|false
|
#
read( )
Advances the reader to the next row in a result set.
Advances the reader to the next row in a result set.
Returns
array|false the current row, false if no more row available
|
public
mixed|false
|
#
readColumn( integer $columnIndex )
Returns a single column from the next row of a result set.
Returns a single column from the next row of a result set.
Parameters
- $columnIndex
integer $columnIndex zero-based column index
Returns
mixed|false the column of the current row, false if no more row available
|
public
mixed|false
|
#
readObject( string $className, array $fields )
Returns an object populated with the next row of data.
Returns an object populated with the next row of data.
Parameters
- $className
string $className class name of the object to be created and populated
- $fields
array $fields Elements of this array are passed to the constructor
Returns
mixed|false the populated object, false if no more row of data available
|
public
array
|
#
readAll( )
Reads the whole result set into an array.
Reads the whole result set into an array.
Returns
array the result set (each array element represents a row of data). An empty array
will be returned if the result contains no row.
|
public
boolean
|
#
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.
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.
Returns
boolean Returns true on success or false on failure.
|
public
|
#
close( )
Closes the reader. This frees up the resources allocated for executing this
SQL statement. Read attempts after this method call are unpredictable.
Closes the reader. This frees up the resources allocated for executing this
SQL statement. Read attempts after this method call are unpredictable.
|
public
boolean
|
#
getIsClosed( )
whether the reader is closed or not.
whether the reader is closed or not.
Returns
boolean whether the reader is closed or not.
|
public
integer
|
#
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.
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.
Returns
integer number of rows contained in the result.
|
public
integer
|
#
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.
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.
Returns
integer number of rows contained in the result.
Implementation of
|
public
integer
|
#
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.
Returns the number of columns in the result set. Note, even there's no row in
the reader, this still gives correct column number.
Returns
integer the number of columns in the result set.
|
public
|
#
rewind( )
Resets the iterator to the initial state. This method is required by the
interface Iterator.
Resets the iterator to the initial state. This method is required by the
interface Iterator.
Throws
Implementation of
|
public
integer
|
#
key( )
Returns the index of the current row. This method is required by the
interface Iterator.
Returns the index of the current row. This method is required by the
interface Iterator.
Returns
integer the index of the current row.
Implementation of
|
public
mixed
|
#
current( )
Returns the current row. This method is required by the interface
Iterator.
Returns the current row. This method is required by the interface
Iterator.
Returns
mixed the current row.
Implementation of
|
public
|
#
next( )
Moves the internal pointer to the next row. This method is required by the
interface Iterator.
Moves the internal pointer to the next row. This method is required by the
interface Iterator.
Implementation of
|
public
boolean
|
#
valid( )
Returns whether there is a row of data at current position. This method is
required by the interface Iterator.
Returns whether there is a row of data at current position. This method is
required by the interface Iterator.
Returns
boolean whether there is a row of data at current position.
Implementation of
|