Query Class Reference

Inherited by PagedQuery.

List of all members.

Public Member Functions

Protected Attributes


Member Function Documentation

Query::__construct ( Connection $conn, $sql = null )

 

Create a new Query.
Parameters
Connection $conn
string $sql

Query::setSql ( $sql )

 

Sets the SQL we are using.
Parameters
string $sql

Query::setStart ( $v )

 

Sets the start row or offset.
Parameters
int $v

void Query::setMax ( $v )

 

Sets max rows (limit).
Parameters
int $v

Returns void

array Query::getRows ( )

 

Gets array of rows (hashes).
Returns array string[][] Array of row hashes.
Exceptions
SQLException 

array Query::getRow ( )

 

Gets first rows (hash). Frees resultset.
Returns array string[] First row.
Exceptions
SQLException 

array Query::getCol ( )

 

Gets array of values for first column in result set.
Returns array string[] Array of values for first column.
Exceptions
SQLException 

string Query::getOne ( )

 

Gets value of first column of first returned row.
Returns string Value for first column in first row.
Exceptions
SQLException 

array Query::getAssoc ( $scalar = false )

 

Fetch the entire result set of a query and return it as an associative array using the first column as the key.

Note: column names are not preserved when using this function.

For example, if the table 'mytable' contains:

ID TEXT DATE -------------------------------- 1 'one' 944679408 2 'two' 944679408 3 'three' 944679408

$q = new Query("SELECT id, text FROM mytable") $q->getAssoc() returns: array( '1' => array('one'), '2' => array('two'), '3' => array('three'), )

... or call $q->getAssoc($scalar=true) to avoid wrapping results in an array (only applies if only 2 cols are returned): array( '1' => 'one', '2' => 'two', '3' => 'three', ) Keep in mind that database functions in PHP usually return string values for results regardless of the database's internal type.

Parameters
boolean $scalar Used only when the query returns exactly two columns. If TRUE, the values of second column are not wrapped in an array. Default here is false, in order to assure expected behavior.

Returns array Associative array with results from the query.
Author Lukas Smith <smith@backendmedia.com> (MDB)

QueryDataSet Query::getDataSet ( )

 

Gets a QueryDataSet representing results of this query.

The QueryDataSet that is returned will be ready to use (records will already have been fetched). Currently only QueryDataSets are returned, so you will not be able to manipulate (update/delete/insert) Record objects in returned DataSet.

$q = new Query("SELECT * FROM author"); $q->setLimit(10); $qds = $q->getDataSet(); foreach($q->getDataSet() as $rec) { $rec->getValue("name"); }

Returns QueryDataSet QDS containing the results.


Member Data Documentation

Connection Query::$conn [protected]

 

string The SQL query. Query::$sql [protected]

 

Query::$start = 0 [protected]

 


This file is part of the Creole[php5] library.


Copyright © 2004 Hans Lellelid  
Creole[php5] CVS