DBResult Class Reference
[Database ObjectsDatabase Interfaces]

Represents the results of a query from DBI2. More...

Inheritance diagram for DBResult:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($cookie, $link)
 Creates a new DBResult object.
 free ()
 Frees MySQL's internal result set object.
 getInsertId ()
 Retrieves primary key for newly inserted rows.
 getRow ($n)
 Retrieves a particular row in the result set.
 nextRow ()
 Retrieves next row in result set.
 numRows ()
 Retrieves the number of rows in the result set.
 reset ()
 Resets current row to the first row in the result set.
 seek ($n)
 Sets the current row to the specified row index.
 toArray ()
 Converts entire result set to array.


Detailed Description

Represents the results of a query from DBI2.

An object of this class is returned by DBI2::select() and DBI2::query(). It contains methods that allow one to grab all or parts of the results returned by a SELECT query. In the former case, it behaves like the old DBI2 and a giant array is generated (with the toArray() method). In the later case, you can ask about specific rows, or iterate row by row. This results in less overhead as giant arrays do not need to be generated or duplicated.


Constructor & Destructor Documentation

DBResult::__construct ( cookie,
link 
)

Creates a new DBResult object.

You should not create DBResult objects directly. They will be returned from DBI2 from methods like select() and query(). The documentation provided here is only for completeness.

Parameters:
$cookie [resource]: result cookie returned from mysql_query()
$link [resource]: MySQL connection link


Member Function Documentation

DBResult::free (  ) 

Frees MySQL's internal result set object.

MySQL doesn't automatically clean up result cookies. This method does that, so that the result set objects that MySQL uses don't stay in memory forever. This method will be called automatically by the destructor of this class. The destructor will not be called if there are still references to the DBResult object, so be careful when passing around references to DBResult objects.

DBResult::getInsertId (  ) 

Retrieves primary key for newly inserted rows.

When a new row is inserted and it has an auto-increment field as a primary key, MySQL generates a new ID for that row automatically and this ID can be retrieved using this method. This method essentially wraps mysql_insert_id().

Returns:
[int]: new primary key value, or false if there was an error

DBResult::getRow ( n  ) 

Retrieves a particular row in the result set.

This method takes a row number, starting from zero, and returns the contents of that row, using mysql_fetch_assoc(). The current row is set to be the given row number and so calls to nextRow() will get rows starting after the given row. That is, a call to nextRow() after getRow() will return the row after the one just retrieved with getRow().

Parameters:
$n [int]: numeric index of the row to retrieve, starting from zero
Returns:
[array]: associative array containing row, or false if there was an error

DBResult::nextRow (  ) 

Retrieves next row in result set.

When called for the first time, this method will retrieve the first row in the result set using mysql_fetch_assoc(), which returns an associative array for the row in the result set. Subsequent calls will retrieve subsequent rows. If there are no more rows, false is returned. If there was an error, null is returned and an error is set on this object. You can reset the current row with reset(), or seek to a particular row with getRow().

Returns:
[array]: next row from result set, false if no more rows and null on error

DBResult::numRows (  ) 

Retrieves the number of rows in the result set.

Returns:
[int]: number of rows in result set, or false on error

DBResult::reset (  ) 

Resets current row to the first row in the result set.

After calling this method, a call to nextRow() will return the first row of the set and continue from there. No data is lost in this operation.

Returns:
[boolean]: success or failure

DBResult::seek ( n  ) 

Sets the current row to the specified row index.

The row index is zero based. A call to nextRow() after this method will return the contents of the row specified by the parameter to this method. As such, seek(n) followed by nextRow() is exactly equivalent to getRow(n).

Parameters:
$n [int]: row index to seek to, zero-based
Returns:
[boolean]: success or failure

DBResult::toArray (  ) 

Converts entire result set to array.

The array is two levels deep. There is one entry in the top-level array for each row in the result set. And each entry is an associative array containing the data for each row, keyed by field name. The top-level array is keyed by row number, starting at zero (i.e., it is a plain, non-associative array). Multiple calls to this method will not generate the array multiple times, rather, the array created on the first call will be returned in subsequent calls. Furthermore, if the current row, as selected by nextRow() or getRow() will not be disturbed by a call to this method.

Returns:
[array]: array representation of result set or null on error


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:02:19 2010 for Common by  doxygen 1.5.6