Class DBLArrayQuery

Description

Query returning values from a (static) array as rows.

This is a simple non-db query. When created, it is passed an array of arrays (data array). It does not support conditions, order, etc. The only two functions it implements are search(), which resets the data array, and nextRecord(), which fetches next element from the data array and returns it.

So the data array should look like: $data = array( array( "id" => 1, "name" => "Element 1", "note" => "Test element" ), array( "id" => 2, "name" => "Element 2", "note" => "Test element" ), ... )

This class can be used in places where a query is required and where you want the query to return a "custom" set of rows. You may, e.g., fetch the data from the database, do some complicated processing and then create a DBLArrayQuery object and pass it to DBLView::detail(). (Or you may make new class as a subclass of the database class you use, e.g., DBLMYSQLQuery and override the nextRecord() method to modify records. This solution is a bit cleaner.)

The other purpose of this class is to serve as an example of custom query. Similar way, you could create a query to return data stored in a file.

Located in /DBLArrayQuery.php (line 37)

DBLQuery
   |
   --DBLArrayQuery
Variable Summary
array $data
Method Summary
DBLArrayQuery DBLArrayQuery (mixed $data, array $dataArray)
mixed nextRecord ()
int search ()
Variables
Methods
Constructor DBLArrayQuery (line 51)

Constructor.

DBLArrayQuery DBLArrayQuery (mixed $data, array $dataArray)
  • array $dataArray: Data to return as records. See class description for the description how the data array should look like. (The array is copied, not referenced.)
nextRecord (line 74)

Get next "record" - next array element.

  • return: Returns record in the array form name => value, or false if there is no next record.
mixed nextRecord ()

Redefinition of:
DBLQuery::nextRecord()
Gets next record from a result set.
search (line 62)

"Start searching".

For this class, it means reseting the array so we start getting the rows from the beginning.

  • return: Returns number of rows.
int search ()

Redefinition of:
DBLQuery::search()
Starts retrieving data from the data source.

Inherited Methods

Inherited From DBLQuery

DBLQuery::DBLQuery()
DBLQuery::addCondition()
DBLQuery::addRecord()
DBLQuery::addValue()
DBLQuery::clearConditions()
DBLQuery::clearValues()
DBLQuery::deleteRecord()
DBLQuery::formatDateTime()
DBLQuery::getDefaultDateTime()
DBLQuery::isEmptyDateTime()
DBLQuery::modifyRecord()
DBLQuery::nextRecord()
DBLQuery::parseDateTime()
DBLQuery::reset()
DBLQuery::search()
DBLQuery::setFields()
DBLQuery::setLimit()
DBLQuery::setOrder()
DBLQuery::setSource()

Documentation generated on Mon, 6 Sep 2004 21:57:00 +0200 by phpDocumentor 1.2.3