## Zend_Db_Select

Description

Class for SQL SELECT generation and results.

- license: New BSD License
- copyright: Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)

Located in /Zend/Db/Select.php (line 36)

Variable Summary
Zend_Db_Adapter_Abstract $_adapter
array $_parts
array $_tableCols
Method Summary
Zend_Db_Select __construct (Zend_Db_Adapter_Abstract $adapter)
Zend_Db_Select distinct ([bool $flag = true])
Zend_Db_Select forUpdate ([bool $flag = true])
Zend_Db_Select from (string $name, [array|string $cols = '*'])
void group (string|array $spec)
void having (string $cond, string $val)
Zend_Db_Select join (string $name, string $cond, [array|string $cols = null])
Zend_Db_Select joinInner (string $name, string $cond, [array|string $cols = null])
Zend_Db_Select joinLeft (string $name, string $cond, [array|string $cols = null])
void limit ([int $count = null], [int $offset = null])
void limitPage (int $page, int $rowCount)
void order (string|array $spec)
void orHaving (string $cond, string $val)
void orWhere (string $cond, string $val)
void where (string $cond, string $val)
Zend_Db_Select _join (null|string $type, string $name, string $cond, array|string $cols)
void _tableCols (string $tbl, string|array $cols)
string __toString ()
Variables
Zend_Db_Adapter_Abstract $_adapter (line 43)

Zend_Db_Adapter_Abstract object.

- access: protected

array $_parts = array(
'distinct' => false,
'forUpdate' => false,
'cols' => array(),'from'=>array(),'join'=>array(),'where'=>array(),'group'=>array(),'having'=>array(),'order'=>array(),'limitCount'=>null,'limitOffset'=>null,) (line 50)

The component parts of a SELECT statement.

- access: protected

array $_tableCols = array() (line 69)

Tracks which columns are being select from each table and join.

- access: protected

Methods
Constructor __construct (line 77)

Class constructor

- access: public

Zend_Db_Select __construct (Zend_Db_Adapter_Abstract $adapter)

- Zend_Db_Adapter_Abstract $adapter

distinct (line 175)

Makes the query SELECT DISTINCT.

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select distinct ([bool $flag = true])

- bool $flag: Whether or not the SELECT is DISTINCT (default true).

forUpdate (line 188)

Makes the query SELECT FOR UPDATE.

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select forUpdate ([bool $flag = true])

- bool $flag: Whether or not the SELECT is DISTINCT (default true).

from (line 202)

Adds a FROM table and optional columns to the query.

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select from (string $name, [array|string $cols = '*'])

- string $name: The table name.
- array|string $cols: The columns to select from this table.

group (line 368)

Adds grouping to the query.

- access: public

void group (string|array $spec)

- string|array $spec: The column(s) to group by.

having (line 395)

Adds a HAVING condition to the query by AND.

If a value is passed as the second param, it will be quoted and replaced into the condition wherever a question-mark appears. See where() for an example

- access: public

void having (string $cond, string $val)

- string $cond: The HAVING condition.
- string $val: A single value to quote into the condition.

join (line 253)

Adds a JOIN table and columns to the query.

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select join (string $name, string $cond, [array|string $cols = null])

- string $name: The table name.
- string $cond: Join on this condition.
- array|string $cols: The columns to select from the joined table.

joinInner (line 280)

Add an INNER JOIN table and colums to the query

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select joinInner (string $name, string $cond, [array|string $cols = null])

- string $name: The table name.
- string $cond: Join on this condition.
- array|string $cols: The columns to select from the joined table.

joinLeft (line 267)

Add a LEFT JOIN table and colums to the query

- return: This Zend_Db_Select object.
- access: public

Zend_Db_Select joinLeft (string $name, string $cond, [array|string $cols = null])

- string $name: The table name.
- string $cond: Join on this condition.
- array|string $cols: The columns to select from the joined table.

limit (line 475)

Sets a limit count and offset to the query.

- access: public

void limit ([int $count = null], [int $offset = null])

- int $count: The number of rows to return.
- int $offset: Start returning after this many rows.

limitPage (line 490)

Sets the limit and count by page number.

- access: public

void limitPage (int $page, int $rowCount)

- int $page: Limit results to this page number.
- int $rowCount: Use this many rows per page.

order (line 446)

Adds a row order to the query.

- access: public

void order (string|array $spec)

- string|array $spec: The column(s) and direction to order by.

orHaving (line 423)

Adds a HAVING condition to the query by OR.

Otherwise identical to orHaving().

- access: public
- see: Zend_Db_Select::having()

void orHaving (string $cond, string $val)

- string $cond: The HAVING condition.
- string $val: A single value to quote into the condition.

orWhere (line 345)

Adds a WHERE condition to the query by OR.

Otherwise identical to where().

- access: public
- see: Zend_Db_Select::where()

void orWhere (string $cond, string $val)

- string $cond: The WHERE condition.
- string $val: A value to quote into the condition.

where (line 317)

Adds a WHERE condition to the query by AND.

If a value is passed as the second param, it will be quoted and replaced into the condition wherever a question-mark appears. Array values are quoted and comma-separated.

1. // simplest but non-secure
2. $select->where("id = $id");
4. // secure (ID is quoted but matched anyway)
5. $select->where('id = ?', $id);
7. // alternatively, with named binding
8. $select->where('id = :id');

Note that it is more correct to use named bindings in your queries for values other than strings. When you use named bindings, don't forget to pass the values when actually making a query:

1. $db->fetchAll($select, array('id' => 5));

- access: public

void where (string $cond, string $val)

- string $cond: The WHERE condition.
- string $val: A single value to quote into the condition.

_join (line 228)

Populate the $_parts 'join' key

Does the dirty work of populating the join key.

- return: This Zend_Db_Select object
- access: protected

Zend_Db_Select _join (null|string $type, string $name, string $cond, array|string $cols)

- null|string $type: Type of join; inner, left, and null are currently supported
- string $name: Table name
- string $cond: Join on this condition
- array|string $cols: The columns to select from the joined table

_tableCols (line 508)

Adds to the internal table-to-column mapping array.

- access: protected

void _tableCols (string $tbl, string|array $cols)

- string $tbl: The table/join the columns come from.
- string|array $cols: The list of columns; preferably as an array, but possibly as a comma-separated string.

__toString (line 88)

Converts this object to an SQL SELECT string.

- return: This object as a SELECT string.
- access: public

string __toString ()

Documentation generated on Tue, 11 Jul 2006 12:18:04 -0500 by phpDocumentor 1.3.0RC6