Class Zend_Db_Select

Description

Class for SQL SELECT generation and results.

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

Located in /Db/Select.php (line 45)


	
			
Class Constant Summary
 COLUMNS = 'columns'
 CROSS_JOIN = 'cross join'
 DISTINCT = 'distinct'
 FOR_UPDATE = 'forupdate'
 FROM = 'from'
 FULL_JOIN = 'full join'
 GROUP = 'group'
 HAVING = 'having'
 INNER_JOIN = 'inner join'
 LEFT_JOIN = 'left join'
 LIMIT_COUNT = 'limitcount'
 LIMIT_OFFSET = 'limitoffset'
 NATURAL_JOIN = 'natural join'
 ORDER = 'order'
 RIGHT_JOIN = 'right join'
 WHERE = 'where'
Variable Summary
Method Summary
 Zend_Db_Select distinct ([bool $flag = true])
 Zend_Db_Select forUpdate ([bool $flag = true])
 Zend_Db_Select from (array|string|Zend_Db_Expr $name, [array|string|Zend_Db_Expr $cols = '*'], [string $schema = null])
 mixed getPart (string $part)
 Zend_Db_Select group (array|string $spec)
 Zend_Db_Select __construct (Zend_Db_Adapter_Abstract $adapter)
 Zend_Db_Select having (string $cond, string|Zend_Db_Expr $val)
 Zend_Db_Select join (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinCross (array|string|Zend_Db_Expr $name, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinFull (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinInner (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinLeft (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinNatural (array|string|Zend_Db_Expr $name, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select joinRight (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
 Zend_Db_Select limit ([int $count = null], [int $offset = null])
 Zend_Db_Select limitPage (int $page, int $rowCount)
 Zend_Db_Select order (mixed $spec)
 Zend_Db_Select orHaving (string $cond, string $val)
 Zend_Db_Select orWhere (string $cond, string $val)
 PDO_Statement|Zend_Db_Statement query ([integer $fetchMode = null])
 Zend_Db_Select reset ([string $part = null])
 Zend_Db_Select where (string $cond, string $val)
 Zend_Db_Select _join (null|string $type, array|string|Zend_Db_Expr $name, string $cond, array|string $cols, [string $schema = null])
 void _tableCols ( $correlationName, mixed $cols, string $tbl)
 string __toString ()
Variables
static array $_partsInit = array(
self::DISTINCT => false,
self::FOR_UPDATE => false,
self::COLUMNS => array(),self::FROM=>array(),self::WHERE=>array(),self::GROUP=>array(),self::HAVING=>array(),self::ORDER=>array(),self::LIMIT_COUNT=>null,self::LIMIT_OFFSET=>null,)
(line 78)

The initial values for the $_parts array.

  • access: protected
Zend_Db_Adapter_Abstract $_adapter (line 71)

Zend_Db_Adapter_Abstract object.

  • access: protected
array $_parts = array() (line 97)

The component parts of a SELECT statement.

Initialized to the $_partsInit array in the constructor.

  • access: protected
array $_tableCols = array() (line 104)

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

  • access: protected
Methods
distinct (line 266)

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 278)

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 FOR UPDATE (default true).
from (line 308)

Adds a FROM table and optional columns to the query.

The first parameter $name can be a simple string, in which case the correlation name is generated automatically. If you want to specify the correlation name, the first parameter must be an associative array in which the key is the physical table name, and the value is the correlation name. For example, array('table' => 'alias'). The correlation name is prepended to all columns fetched for this table.

The second parameter can be a single string or Zend_Db_Expr object, or else an array of strings or Zend_Db_Expr objects.

The first parameter can be null or an empty string, in which case no correlation name is generated or prepended to the columns named in the second parameter.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select from (array|string|Zend_Db_Expr $name, [array|string|Zend_Db_Expr $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name or an associative array relating table name to correlation name.
  • array|string|Zend_Db_Expr $cols: The columns to select from this table.
  • string $schema: The schema name to specify, if any.
getPart (line 815)

Get part of the structured information for the currect query.

  • throws: Zend_Db_Select_Exception
  • access: public
mixed getPart (string $part)
  • string $part
group (line 628)

Adds grouping to the query.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select group (array|string $spec)
  • array|string $spec: The column(s) to group by.
Constructor __construct (line 111)

Class constructor

  • access: public
Zend_Db_Select __construct (Zend_Db_Adapter_Abstract $adapter)
having (line 655)

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

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select having (string $cond, string|Zend_Db_Expr $val)
  • string $cond: The HAVING condition.
  • string|Zend_Db_Expr $val: A single value to quote into the condition.
join (line 420)

Adds a JOIN table and columns to the query.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select join (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • string $cond: Join on this condition.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinCross (line 523)

Add a CROSS JOIN table and colums to the query.

A cross join is a cartesian product; there is no join condition.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinCross (array|string|Zend_Db_Expr $name, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinFull (line 506)

Add a FULL OUTER JOIN table and colums to the query.

A full outer join is like combining a left outer join and a right outer join. All rows from both tables are included, paired with each other on the same row of the result set if they satisfy the join condition, and otherwise paired with NULLs in place of columns from the other table.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinFull (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • string $cond: Join on this condition.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinInner (line 441)

Add an INNER JOIN table and colums to the query

Rows in both tables are matched according to the expression in the $cond argument. The result set is comprised of all cases where rows from the left table match rows from the right table.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinInner (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • string $cond: Join on this condition.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinLeft (line 462)

Add a LEFT OUTER JOIN table and colums to the query

All rows from the left operand table are included, matching rows from the right operand table included, and the columns from the right operand table are filled with NULLs if no row exists matching the left table.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinLeft (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • string $cond: Join on this condition.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinNatural (line 543)

Add a NATURAL JOIN table and colums to the query.

A natural join assumes an equi-join across any column(s) that appear with the same name in both tables. Only natural inner joins are supported by this API, even though SQL permits natural outer joins as well.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinNatural (array|string|Zend_Db_Expr $name, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
joinRight (line 484)

Add a RIGHT OUTER JOIN table and colums to the query.

Right outer join is the complement of left outer join. All rows from the right operand table are included, matching rows from the left operand table included, and the columns from the left operand table are filled with NULLs if no row exists matching the right table.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select joinRight (array|string|Zend_Db_Expr $name, string $cond, [array|string $cols = '*'], [string $schema = null])
  • array|string|Zend_Db_Expr $name: The table name.
  • string $cond: Join on this condition.
  • array|string $cols: The columns to select from the joined table.
  • string $schema: The database name to specify, if any.
limit (line 744)

Sets a limit count and offset to the query.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select limit ([int $count = null], [int $offset = null])
  • int $count: OPTIONAL The number of rows to return.
  • int $offset: OPTIONAL Start returning after this many rows.
limitPage (line 758)

Sets the limit and count by page number.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select limitPage (int $page, int $rowCount)
  • int $page: Limit results to this page number.
  • int $rowCount: Use this many rows per page.
order (line 704)

Adds a row order to the query.

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select order (mixed $spec)
  • mixed $spec: The column(s) and direction to order by.
orHaving (line 682)

Adds a HAVING condition to the query by OR.

Otherwise identical to orHaving().

Zend_Db_Select orHaving (string $cond, string $val)
  • string $cond: The HAVING condition.
  • string $val: A single value to quote into the condition.
orWhere (line 606)

Adds a WHERE condition to the query by OR.

Otherwise identical to where().

Zend_Db_Select orWhere (string $cond, string $val)
  • string $cond: The WHERE condition.
  • string $val: A value to quote into the condition.
query (line 828)
  • access: public
PDO_Statement|Zend_Db_Statement query ([integer $fetchMode = null])
  • integer $fetchMode: OPTIONAL
reset (line 844)

Clear parts of the Select object, or an individual part.

  • access: public
Zend_Db_Select reset ([string $part = null])
  • string $part: OPTIONAL
where (line 579)

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");
  3.  
  4.  // secure (ID is quoted but matched anyway)
  5.  $select->where('id = ?'$id);
  6.  
  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($selectarray('id' => 5));

  • return: This Zend_Db_Select object.
  • access: public
Zend_Db_Select where (string $cond, string $val)
  • string $cond: The WHERE condition.
  • string $val: A single value to quote into the condition.
_join (line 329)

Populate the $_parts 'join' key

Does the dirty work of populating the join key.

The $name and $cols parameters follow the same logic as described in the from() method.

  • return: This Zend_Db_Select object
  • throws: Zend_Db_Select_Exception
  • access: protected
Zend_Db_Select _join (null|string $type, array|string|Zend_Db_Expr $name, string $cond, array|string $cols, [string $schema = null])
  • null|string $type: Type of join; inner, left, and null are currently supported
  • array|string|Zend_Db_Expr $name: Table name
  • string $cond: Join on this condition
  • array|string $cols: The columns to select from the joined table
  • string $schema: The database name to specify, if any.
_tableCols (line 775)

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

  • access: protected
void _tableCols ( $correlationName, mixed $cols, string $tbl)
  • string $tbl: The table/join the columns come from.
  • mixed $cols: The list of columns; preferably as an array, but possibly as a string containing one column.
  • $correlationName
__toString (line 126)

Converts this object to an SQL SELECT string.

  • return: This object as a SELECT string.
  • todo: use $this->_adapter->quoteColumns() for non-PDO adapters
  • todo: use $this->_adapter->quoteTableNames() for non-PDO adapters
  • todo: use prepared queries for PDO adapters instead of constructing all the SQL ourselves like in Adapter/Abstract.php.html:query()
  • access: public
string __toString ()
Class Constants
COLUMNS = 'columns' (line 50)
CROSS_JOIN = 'cross join' (line 63)
DISTINCT = 'distinct' (line 48)
FOR_UPDATE = 'forupdate' (line 49)
FROM = 'from' (line 51)
FULL_JOIN = 'full join' (line 62)
GROUP = 'group' (line 53)
HAVING = 'having' (line 54)
INNER_JOIN = 'inner join' (line 59)
LEFT_JOIN = 'left join' (line 60)
LIMIT_COUNT = 'limitcount' (line 56)
LIMIT_OFFSET = 'limitoffset' (line 57)
NATURAL_JOIN = 'natural join' (line 64)
ORDER = 'order' (line 55)
RIGHT_JOIN = 'right join' (line 61)
WHERE = 'where' (line 52)

Documentation generated on Sun, 27 May 2007 23:27:27 -0700 by phpDocumentor 1.3.2