TDbDataReader class.
TDbDataReader 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 TDbDataReader by using foreach:
- foreach($reader as $row)
- // $row represents a row of data
Since TDbDataReader 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.
Method Summary |
void
|
bindColumn
( mixed $column, mixed &$value, int $dataType)
Binds a column to a PHP variable.
|
void
|
Closes the reader.
|
mixed
|
Returns the current row.
|
int
|
|
boolean
|
|
int
|
|
integer
|
Returns the index of the current row.
|
void
|
Moves the internal pointer to the next row.
|
void
|
Advances the reader to the next result when reading the results of a batch of statements.
|
array|false
|
Advances the reader to the next row in a result set.
|
array
|
Reads the whole result set into an array.
|
mixed|false
|
Returns a single column from the next row of a result set.
|
mixed|false
|
Returns a single column from the next row of a result set.
|
void
|
Resets the iterator to the initial state.
|
void
|
|
boolean
|
Returns whether there is a row of data at current position.
|
Method Details |
bindColumn
public void bindColumn |
(mixed $column , mixed &$value , int $dataType ) |
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.
Input |
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. |
mixed | &$value | Name of the PHP variable to which the column will be bound. |
int | $dataType | Data type of the parameter |
Output |
Exception |
|
close
Closes the reader.
Any further data reading will result in an exception.
|
current
Returns the current row.
This method is required by the interface Iterator.
Output |
mixed
| the current row. |
Exception |
|
getColumnCount
public int getColumnCount |
() |
Output |
int
| the number of columns in the result set. Note, even there's no row in the reader, this still gives correct column number. |
Exception |
|
getIsClosed
public boolean getIsClosed |
() |
Output |
boolean
| whether the reader is closed or not. |
Exception |
|
getRowCount
public int getRowCount |
() |
Output |
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. |
Exception |
|
key
Returns the index of the current row.
This method is required by the interface Iterator.
Output |
integer
| the index of the current row. |
Exception |
|
next
Moves the internal pointer to the next row.
This method is required by the interface Iterator.
|
nextResult
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
public array|false read |
() |
Advances the reader to the next row in a result set.
Output |
array|false
| the current row, false if no more row available |
Exception |
|
readAll
Reads the whole result set into an array.
Output |
array
| the result set (each array element represents a row of data). An empty array will be returned if the result contains no row. |
Exception |
|
readColumn
public mixed|false readColumn |
(int $columnIndex ) |
Returns a single column from the next row of a result set.
Input |
int | $columnIndex | zero-based column index |
Output |
mixed|false
| the column of the current row, false if no more row available |
Exception |
|
readObject
public mixed|false readObject |
(string $className , array $fields ) |
Returns a single column from the next row of a result set.
Input |
string | $className | class name of the object to be created and populated |
array | $fields | list of column names whose values are to be passed as parameters in the constructor of the class being created |
Output |
mixed|false
| the populated object, false if no more row of data available |
Exception |
|
rewind
Resets the iterator to the initial state.
This method is required by the interface Iterator.
Output |
Exception |
throws | TDbException if this method is invoked twice |
|
setFetchMode
public void setFetchMode |
(mixed $mode ) |
Input |
mixed | $mode | |
Output |
Exception |
|
valid
Returns whether there is a row of data at current position.
This method is required by the interface Iterator.
Output |
boolean
| whether there is a row of data at current position. |
Exception |
|