Query Class Reference

Inherited by PagedQuery.

List of all members.

Public Member Functions

Public Attributes


Constructor & Destructor Documentation

Query::Query ( &$  conn,  $  sql = null )

 

Create a new Query.

Parameters:
Connection $conn
string $sql


Member Function Documentation

Query::setSql ( $  sql)

 

Sets the SQL we are using.

Parameters:
string $sql

Query::setStart ( $  v)

 

Sets the start row or offset.

Parameters:
int $v

Query::setMax ( $  v)

 

Sets max rows (limit).

Parameters:
int $v

Returns void

& Query::getRows ()

 

Gets array of rows (hashes).

Returns mixed array string[][] Array of row hashes on success, SQLException on failure.

& Query::getRow ()

 

Gets first rows (hash). Frees resultset.

Returns mixed array string[] First row on success, SQLException on failure.

& Query::getCol ()

 

Gets array of values for first column in result set.

Returns mixed array string[] Array of values for first column on sucess, SQLException on failure.

& Query::getOne ()

 

Gets value of first column of first returned row.

Returns mixed string Value for first column in first row on success, SQLException on failure.

& 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 mixed array Associative array with results from the query on success, SQLException on failure.

Author Lukas Smith <smith@backendmedia.com> (MDB)

& 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 mixed QueryDataSet QDS containing the results on success, SQL- or DataSetException on failure.


Member Data Documentation

Connection var Query::$conn

 

string The SQL query. var Query::$sql

 

Query::$start = 0

 


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


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS