Class TDbDataReader

Description

Implements interfaces:

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:

  1. foreach($reader as $row)
  2. // $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.

  • since: 3.0
  • version: $Id: TDbDataReader.php 2386 2008-03-06 15:25:32Z xue $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Data/TDbDataReader.php (line 37)

TComponent
   |
   --TDbDataReader
Method Summary
TDbDataReader __construct (TDbCommand $command)
void bindColumn (mixed $column, mixed &$value, [int $dataType = null])
void close ()
mixed current ()
boolean getIsClosed ()
int getRowCount ()
integer key ()
void next ()
void nextResult ()
array|false read ()
array readAll ()
mixed|false readColumn (int $columnIndex)
mixed|false readObject (string $className, array $fields)
void rewind ()
void setFetchMode (mixed $mode)
boolean valid ()
Methods
Constructor __construct (line 48)

Constructor.

  • access: public
TDbDataReader __construct (TDbCommand $command)
  • TDbCommand $command: the command generating the query result
bindColumn (line 65)

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.

void bindColumn (mixed $column, mixed &$value, [int $dataType = null])
  • 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
close (line 136)

Closes the reader.

Any further data reading will result in an exception.

  • access: public
void close ()
current (line 200)

Returns the current row.

This method is required by the interface Iterator.

  • return: the current row.
  • access: public
mixed current ()
getColumnCount (line 164)
  • return: the number of columns in the result set. Note, even there's no row in the reader, this still gives correct column number.
  • access: public
int getColumnCount ()
getIsClosed (line 145)
  • return: whether the reader is closed or not.
  • access: public
boolean getIsClosed ()
getRowCount (line 155)
  • return: 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.
  • access: public
int getRowCount ()
key (line 190)

Returns the index of the current row.

This method is required by the interface Iterator.

  • return: the index of the current row.
  • access: public
integer key ()
next (line 209)

Moves the internal pointer to the next row.

This method is required by the interface Iterator.

  • access: public
void next ()
nextResult (line 127)

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.

  • access: public
void nextResult ()
read (line 86)

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

  • return: the current row, false if no more row available
  • access: public
array|false read ()
readAll (line 117)

Reads the whole result set into an array.

  • return: the result set (each array element represents a row of data). An empty array will be returned if the result contains no row.
  • access: public
array readAll ()
readColumn (line 96)

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

  • return: the column of the current row, false if no more row available
  • access: public
mixed|false readColumn (int $columnIndex)
  • int $columnIndex: zero-based column index
readObject (line 107)

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

  • return: the populated object, false if no more row of data available
  • access: public
mixed|false readObject (string $className, array $fields)
  • 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
rewind (line 174)

Resets the iterator to the initial state.

This method is required by the interface Iterator.

  • access: public
  • throws: TDbException if this method is invoked twice
void rewind ()
setFetchMode (line 76)
void setFetchMode (mixed $mode)
valid (line 220)

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

This method is required by the interface Iterator.

  • return: whether there is a row of data at current position.
  • access: public
boolean valid ()

Inherited Methods

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Mon, 21 Apr 2008 11:34:53 -0400 by phpDocumentor 1.3.0RC4