abstract class Query implements IteratorAggregate (View source)

Abstract query-result class. A query result is an iterable that returns a map for each record of a query result.

This should be subclassed by an actual database implementation. It will only ever be constructed by a subclass of Database. The result of a database query - an iterable object that's returned by by various low-level ORM methods.

Primarily, the Query class takes care of the iterator plumbing, letting the subclasses focusing on providing the specific data-access methods that are required.

The map should be keyed by the column names, and the values should use the following types:

  • boolean returned as integer 1 or 0 (to ensure consistency with MySQL that doesn't have native booleans)
  • integer types returned as integers
  • floating point / decimal types returned as floats
  • strings returned as strings
  • dates / datetimes returned as strings

Methods

public
array
column(string $column = null)

Return an array containing all the values from a specific column. If no column is set, then the first will be returned

public
array
keyedColumn()

Return an array containing all values in the leftmost column, where the keys are the same as the values.

public
array
map()

Return a map from the first column to the second column.

public
array
record()

Returns the first record in the result

public
string
value()

Returns the first column of the first record.

public
string
table()

Return an HTML table containing the full result-set

public
getIterator()

Return the next record in the query result.

public
int
numRecords()

Return the total number of items in the query result.

Details

array column(string $column = null)

Return an array containing all the values from a specific column. If no column is set, then the first will be returned

Parameters

string $column

Return Value

array

array keyedColumn()

Return an array containing all values in the leftmost column, where the keys are the same as the values.

Return Value

array

array map()

Return a map from the first column to the second column.

Return Value

array

array record()

Returns the first record in the result

Return Value

array

string value()

Returns the first column of the first record.

Return Value

string

string table()

Return an HTML table containing the full result-set

Return Value

string

abstract Traversable getIterator()

Return the next record in the query result.

Return Value

Traversable

abstract int numRecords()

Return the total number of items in the query result.

Return Value

int