Db/Table/Select.php

Show: inherited
Table of Contents

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Db  
Subpackage
Select  
Version
$Id: Select.php 24593 2012-01-05 20:35:02Z matthew $  

\Zend_Db_Table_Select

Package: Zend\Db\Table

Class for SQL SELECT query manipulation for the Zend_Db_Table component.

Parent(s)
\Zend_Db_Select
Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

Constant  DISTINCT = 'distinct'
inheritedInherited from: \Zend_Db_Select::DISTINCT
Inherited_from
\Zend_Db_Select::DISTINCT  
Constant  COLUMNS = 'columns'
inheritedInherited from: \Zend_Db_Select::COLUMNS
Inherited_from
\Zend_Db_Select::COLUMNS  
Constant  FROM = 'from'
inheritedInherited from: \Zend_Db_Select::FROM
Inherited_from
\Zend_Db_Select::FROM  
Constant  UNION = 'union'
inheritedInherited from: \Zend_Db_Select::UNION
Inherited_from
\Zend_Db_Select::UNION  
Constant  WHERE = 'where'
inheritedInherited from: \Zend_Db_Select::WHERE
Inherited_from
\Zend_Db_Select::WHERE  
Constant  GROUP = 'group'
inheritedInherited from: \Zend_Db_Select::GROUP
Inherited_from
\Zend_Db_Select::GROUP  
Constant  HAVING = 'having'
inheritedInherited from: \Zend_Db_Select::HAVING
Inherited_from
\Zend_Db_Select::HAVING  
Constant  ORDER = 'order'
inheritedInherited from: \Zend_Db_Select::ORDER
Inherited_from
\Zend_Db_Select::ORDER  
Constant  LIMIT_COUNT = 'limitcount'
inheritedInherited from: \Zend_Db_Select::LIMIT_COUNT
Inherited_from
\Zend_Db_Select::LIMIT_COUNT  
Constant  LIMIT_OFFSET = 'limitoffset'
inheritedInherited from: \Zend_Db_Select::LIMIT_OFFSET
Inherited_from
\Zend_Db_Select::LIMIT_OFFSET  
Constant  FOR_UPDATE = 'forupdate'
inheritedInherited from: \Zend_Db_Select::FOR_UPDATE
Inherited_from
\Zend_Db_Select::FOR_UPDATE  
Constant  INNER_JOIN = 'inner join'
inheritedInherited from: \Zend_Db_Select::INNER_JOIN
Inherited_from
\Zend_Db_Select::INNER_JOIN  
Constant  LEFT_JOIN = 'left join'
inheritedInherited from: \Zend_Db_Select::LEFT_JOIN
Inherited_from
\Zend_Db_Select::LEFT_JOIN  
Constant  RIGHT_JOIN = 'right join'
inheritedInherited from: \Zend_Db_Select::RIGHT_JOIN
Inherited_from
\Zend_Db_Select::RIGHT_JOIN  
Constant  FULL_JOIN = 'full join'
inheritedInherited from: \Zend_Db_Select::FULL_JOIN
Inherited_from
\Zend_Db_Select::FULL_JOIN  
Constant  CROSS_JOIN = 'cross join'
inheritedInherited from: \Zend_Db_Select::CROSS_JOIN
Inherited_from
\Zend_Db_Select::CROSS_JOIN  
Constant  NATURAL_JOIN = 'natural join'
inheritedInherited from: \Zend_Db_Select::NATURAL_JOIN
Inherited_from
\Zend_Db_Select::NATURAL_JOIN  
Constant  SQL_WILDCARD = '*'
inheritedInherited from: \Zend_Db_Select::SQL_WILDCARD
Inherited_from
\Zend_Db_Select::SQL_WILDCARD  
Constant  SQL_SELECT = 'SELECT'
inheritedInherited from: \Zend_Db_Select::SQL_SELECT
Inherited_from
\Zend_Db_Select::SQL_SELECT  
Constant  SQL_UNION = 'UNION'
inheritedInherited from: \Zend_Db_Select::SQL_UNION
Inherited_from
\Zend_Db_Select::SQL_UNION  
Constant  SQL_UNION_ALL = 'UNION ALL'
inheritedInherited from: \Zend_Db_Select::SQL_UNION_ALL
Inherited_from
\Zend_Db_Select::SQL_UNION_ALL  
Constant  SQL_FROM = 'FROM'
inheritedInherited from: \Zend_Db_Select::SQL_FROM
Inherited_from
\Zend_Db_Select::SQL_FROM  
Constant  SQL_WHERE = 'WHERE'
inheritedInherited from: \Zend_Db_Select::SQL_WHERE
Inherited_from
\Zend_Db_Select::SQL_WHERE  
Constant  SQL_DISTINCT = 'DISTINCT'
inheritedInherited from: \Zend_Db_Select::SQL_DISTINCT
Inherited_from
\Zend_Db_Select::SQL_DISTINCT  
Constant  SQL_GROUP_BY = 'GROUP BY'
inheritedInherited from: \Zend_Db_Select::SQL_GROUP_BY
Inherited_from
\Zend_Db_Select::SQL_GROUP_BY  
Constant  SQL_ORDER_BY = 'ORDER BY'
inheritedInherited from: \Zend_Db_Select::SQL_ORDER_BY
Inherited_from
\Zend_Db_Select::SQL_ORDER_BY  
Constant  SQL_HAVING = 'HAVING'
inheritedInherited from: \Zend_Db_Select::SQL_HAVING
Inherited_from
\Zend_Db_Select::SQL_HAVING  
Constant  SQL_FOR_UPDATE = 'FOR UPDATE'
inheritedInherited from: \Zend_Db_Select::SQL_FOR_UPDATE
Constant  SQL_AND = 'AND'
inheritedInherited from: \Zend_Db_Select::SQL_AND
Inherited_from
\Zend_Db_Select::SQL_AND  
Constant  SQL_AS = 'AS'
inheritedInherited from: \Zend_Db_Select::SQL_AS
Inherited_from
\Zend_Db_Select::SQL_AS  
Constant  SQL_OR = 'OR'
inheritedInherited from: \Zend_Db_Select::SQL_OR
Inherited_from
\Zend_Db_Select::SQL_OR  
Constant  SQL_ON = 'ON'
inheritedInherited from: \Zend_Db_Select::SQL_ON
Inherited_from
\Zend_Db_Select::SQL_ON  
Constant  SQL_ASC = 'ASC'
inheritedInherited from: \Zend_Db_Select::SQL_ASC
Inherited_from
\Zend_Db_Select::SQL_ASC  
Constant  SQL_DESC = 'DESC'
inheritedInherited from: \Zend_Db_Select::SQL_DESC
Inherited_from
\Zend_Db_Select::SQL_DESC  

Properties

Propertyprotected\Zend_Db_Adapter_Abstract $_adapter =
inherited

Zend_Db_Adapter_Abstract object.

Inherited from: \Zend_Db_Select::$$_adapter
Propertyprotectedarray $_bind = array()
inherited

Bind variables for query

Inherited from: \Zend_Db_Select::$$_bind
Default valuearray()Details
Type
array
Inherited_from
\Zend_Db_Select::$$_bind  
Propertyprotectedarray $_info =

Table schema for parent Zend_Db_Table.

Details
Type
array
Propertyprotectedarray $_integrityCheck = true

Table integrity override.

Default valuetrueDetails
Type
array
Propertyprotectedarray $_joinTypes = array(self::INNER_JOIN, self::LEFT_JOIN, self::RIGHT_JOIN, self::FULL_JOIN, self::CROSS_JOIN, self::NATURAL_JOIN)
staticinherited

Specify legal join types.

Inherited from: \Zend_Db_Select::$$_joinTypes
Default valuearray(self::INNER_JOIN, self::LEFT_JOIN, self::RIGHT_JOIN, self::FULL_JOIN, self::CROSS_JOIN, self::NATURAL_JOIN)Details
Type
array
Inherited_from
\Zend_Db_Select::$$_joinTypes  
Propertyprotectedarray $_parts = array()
inherited

The component parts of a SELECT statement.

Inherited from: \Zend_Db_Select::$$_parts

Initialized to the $_partsInit array in the constructor.

Default valuearray()Details
Type
array
Inherited_from
\Zend_Db_Select::$$_parts  
Propertyprotectedarray $_partsInit = array(self::DISTINCT => false, self::COLUMNS => array(), self::UNION => array(), self::FROM => array(), self::WHERE => array(), self::GROUP => array(), self::HAVING => array(), self::ORDER => array(), self::LIMIT_COUNT => null, self::LIMIT_OFFSET => null, self::FOR_UPDATE => false)
staticinherited

The initial values for the $_parts array.

Inherited from: \Zend_Db_Select::$$_partsInit

NOTE: It is important for the 'FOR_UPDATE' part to be last to ensure meximum compatibility with database adapters.

Default valuearray(self::DISTINCT => false, self::COLUMNS => array(), self::UNION => array(), self::FROM => array(), self::WHERE => array(), self::GROUP => array(), self::HAVING => array(), self::ORDER => array(), self::LIMIT_COUNT => null, self::LIMIT_OFFSET => null, self::FOR_UPDATE => false)Details
Type
array
Inherited_from
\Zend_Db_Select::$$_partsInit  
Propertyprotected\Zend_Db_Table_Abstract $_table =

Table instance that created this select object

Propertyprotectedarray $_tableCols = array()
inherited

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

Inherited from: \Zend_Db_Select::$$_tableCols
Default valuearray()Details
Type
array
Inherited_from
\Zend_Db_Select::$$_tableCols  
Propertyprotectedarray $_unionTypes = array(self::SQL_UNION, self::SQL_UNION_ALL)
staticinherited

Specify legal union types.

Inherited from: \Zend_Db_Select::$$_unionTypes
Default valuearray(self::SQL_UNION, self::SQL_UNION_ALL)Details
Type
array
Inherited_from
\Zend_Db_Select::$$_unionTypes  

Methods

methodpublic__call(string $method, array $args) : \Zend_Db_Select
inherited

Turn magic function calls into non-magic function calls for joinUsing syntax

Inherited from: \Zend_Db_Select::__call()
Parameters
Name Type Description
$method string
$args array

OPTIONAL Zend_Db_Table_Select query modifier

Returns
Type Description
\Zend_Db_Select
Throws
Exception Description
\Zend_Db_Select_Exception If an invalid method is called.
methodpublic__construct( $table) : void

Class constructor

Parameters
Name Type Description
$table
methodpublic__toString() : string
inherited

Implements magic method.

Inherited from: \Zend_Db_Select::__toString()
Returns
Type Description
string This object as a SELECT string.
methodprotected_getDummyTable() : array
inherited

Inherited from: \Zend_Db_Select::_getDummyTable()
Returns
Type Description
array
methodprotected_getQuotedSchema(string $schema = null) : string | null
inherited

Return a quoted schema name

Inherited from: \Zend_Db_Select::_getQuotedSchema()
Parameters
Name Type Description
$schema string

The schema name OPTIONAL

Returns
Type Description
string | null
methodprotected_getQuotedTable(string $tableName, string $correlationName = null) : string
inherited

Return a quoted table name

Inherited from: \Zend_Db_Select::_getQuotedTable()
Parameters
Name Type Description
$tableName string

The table name

$correlationName string

The correlation name OPTIONAL

Returns
Type Description
string
methodprotected_join(null | string $type, array | string | \Zend_Db_Expr $name, string $cond, array | string $cols, string $schema = null) : \Zend_Db_Select
inherited

Populate the {@link $_parts} 'join' key

Inherited from: \Zend_Db_Select::_join()

Does the dirty work of populating the join key.

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

Parameters
Name Type Description
$type null | string

Type of join; inner, left, and null are currently supported

$name array | string | \Zend_Db_Expr

Table name

$cond string

Join on this condition

$cols array | string

The columns to select from the joined table

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object
Throws
Exception Description
\Zend_Db_Select_Exception
methodpublic_joinUsing( $type,  $name,  $cond,  $cols = '*',  $schema = null) : \Zend_Db_Select
inherited

Handle JOIN.

Inherited from: \Zend_Db_Select::_joinUsing()

.. USING... syntax

This is functionality identical to the existing JOIN methods, however the join condition can be passed as a single column name. This method then completes the ON condition by using the same field for the FROM table and the JOIN table.

$select = $db->select()->from('table1')
                       ->joinUsing('table2', 'column1');

// SELECT * FROM table1 JOIN table2 ON table1.column1 = table2.column2

These joins are called by the developer simply by adding 'Using' to the method name. E.g. * joinUsing * joinInnerUsing * joinFullUsing * joinRightUsing * joinLeftUsing

Parameters
Name Type Description
$type
$name
$cond
$cols
$schema
Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodprotected_renderColumns(string $sql) : string | null
inherited

Render DISTINCT clause

Inherited from: \Zend_Db_Select::_renderColumns()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string | null
methodprotected_renderDistinct(string $sql) : string
inherited

Render DISTINCT clause

Inherited from: \Zend_Db_Select::_renderDistinct()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderForupdate(string $sql) : string
inherited

Render FOR UPDATE clause

Inherited from: \Zend_Db_Select::_renderForupdate()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderFrom(string $sql) : string
inherited

Render FROM clause

Inherited from: \Zend_Db_Select::_renderFrom()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderGroup(string $sql) : string
inherited

Render GROUP clause

Inherited from: \Zend_Db_Select::_renderGroup()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderHaving(string $sql) : string
inherited

Render HAVING clause

Inherited from: \Zend_Db_Select::_renderHaving()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderLimitoffset(string $sql) : string
inherited

Render LIMIT OFFSET clause

Inherited from: \Zend_Db_Select::_renderLimitoffset()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderOrder(string $sql) : string
inherited

Render ORDER clause

Inherited from: \Zend_Db_Select::_renderOrder()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderUnion(string $sql) : string
inherited

Render UNION query

Inherited from: \Zend_Db_Select::_renderUnion()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_renderWhere(string $sql) : string
inherited

Render WHERE clause

Inherited from: \Zend_Db_Select::_renderWhere()
Parameters
Name Type Description
$sql string

SQL query

Returns
Type Description
string
methodprotected_tableCols( $correlationName, array | string $cols, bool | string $afterCorrelationName = null) : void
inherited

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

Inherited from: \Zend_Db_Select::_tableCols()
Parameters
Name Type Description
$correlationName
$cols array | string

The list of columns; preferably as an array, but possibly as a string containing one column.

$afterCorrelationName bool | string

True if it should be prepended, a correlation name if it should be inserted

methodprivate_uniqueCorrelation(string | array $name) : string
inherited

Generate a unique correlation name

Inherited from: \Zend_Db_Select::_uniqueCorrelation()
Parameters
Name Type Description
$name string | array

A qualified identifier.

Returns
Type Description
string A unique correlation name.
methodprotected_where(string $condition, mixed $value = null, string $type = null, boolean $bool = true) : string
inherited

Internal function for creating the where clause

Inherited from: \Zend_Db_Select::_where()
Parameters
Name Type Description
$condition string
$value mixed

optional

$type string

optional

$bool boolean

true = AND, false = OR

Returns
Type Description
string clause
methodpublicassemble() : string | null

Performs a validation on the select query before passing back to the parent class.

Ensures that only columns from the primary Zend_Db_Table are returned in the result.

Returns
Type Description
string | null This object as a SELECT string (or null if a string cannot be produced)
methodpublicbind(mixed $bind) : \Zend_Db_Select
inherited

Set bind variables

Inherited from: \Zend_Db_Select::bind()
Parameters
Name Type Description
$bind mixed
Returns
Type Description
\Zend_Db_Select
methodpubliccolumns(array | string | \Zend_Db_Expr $cols = '*', string $correlationName = null) : \Zend_Db_Select
inherited

Specifies the columns used in the FROM clause.

Inherited from: \Zend_Db_Select::columns()

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

Parameters
Name Type Description
$cols array | string | \Zend_Db_Expr

The columns to select from this table.

$correlationName string

Correlation name of target table. OPTIONAL

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicdistinct(bool $flag = true) : \Zend_Db_Select
inherited

Makes the query SELECT DISTINCT.

Inherited from: \Zend_Db_Select::distinct()
Parameters
Name Type Description
$flag bool

Whether or not the SELECT is DISTINCT (default true).

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicforUpdate(bool $flag = true) : \Zend_Db_Select
inherited

Makes the query SELECT FOR UPDATE.

Inherited from: \Zend_Db_Select::forUpdate()
Parameters
Name Type Description
$flag bool

Whether or not the SELECT is FOR UPDATE (default true).

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicfrom(array | string | \Zend_Db_Expr | \Zend_Db_Table_Abstract $name, array | string | \Zend_Db_Expr $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Table_Select

Adds a FROM table and optional columns to the query.

The table name can be expressed

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr | \Zend_Db_Table_Abstract

The table name or an associative array relating table name to correlation name.

$cols array | string | \Zend_Db_Expr

The columns to select from this table.

$schema string

The schema name to specify, if any.

Returns
Type Description
\Zend_Db_Table_Select This Zend_Db_Table_Select object.
methodpublicgetAdapter() : \Zend_Db_Adapter_Abstract
inherited

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Select object.

Inherited from: \Zend_Db_Select::getAdapter()
Returns
Type Description
\Zend_Db_Adapter_Abstract
methodpublicgetBind() : array
inherited

Get bind variables

Inherited from: \Zend_Db_Select::getBind()
Returns
Type Description
array
methodpublicgetPart(string $part) : mixed
inherited

Get part of the structured information for the currect query.

Inherited from: \Zend_Db_Select::getPart()
Parameters
Name Type Description
$part string
Returns
Type Description
mixed
Throws
Exception Description
\Zend_Db_Select_Exception
methodpublicgetTable() : \Zend_Db_Table_Abstract

Return the table that created this select object

Returns
Type Description
\Zend_Db_Table_Abstract
methodpublicgroup(array | string $spec) : \Zend_Db_Select
inherited

Adds grouping to the query.

Inherited from: \Zend_Db_Select::group()
Parameters
Name Type Description
$spec array | string

The column(s) to group by.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublichaving(string $cond, mixed $value = null, int $type = null) : \Zend_Db_Select
inherited

Adds a HAVING condition to the query by AND.

Inherited from: \Zend_Db_Select::having()

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

Parameters
Name Type Description
$cond string

The HAVING condition.

$value mixed

OPTIONAL The value to quote into the condition.

$type int

OPTIONAL The type of the given value

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicisReadOnly() : boolean

Tests query to determine if expressions or aliases columns exist.

Returns
Type Description
boolean
methodpublicjoin(array | string | \Zend_Db_Expr $name, string $cond, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

Adds a JOIN table and columns to the query.

Inherited from: \Zend_Db_Select::join()

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

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cond string

Join on this condition.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinCross(array | string | \Zend_Db_Expr $name, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

Add a CROSS JOIN table and colums to the query.

Inherited from: \Zend_Db_Select::joinCross()

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.

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinFull(array | string | \Zend_Db_Expr $name, string $cond, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

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

Inherited from: \Zend_Db_Select::joinFull()

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.

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cond string

Join on this condition.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinInner(array | string | \Zend_Db_Expr $name, string $cond, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

Add an INNER JOIN table and colums to the query Rows in both tables are matched according to the expression in the $cond argument.

Inherited from: \Zend_Db_Select::joinInner()

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.

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cond string

Join on this condition.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinLeft(array | string | \Zend_Db_Expr $name, string $cond, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

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.

Inherited from: \Zend_Db_Select::joinLeft()

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

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cond string

Join on this condition.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinNatural(array | string | \Zend_Db_Expr $name, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

Add a NATURAL JOIN table and colums to the query.

Inherited from: \Zend_Db_Select::joinNatural()

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.

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicjoinRight(array | string | \Zend_Db_Expr $name, string $cond, array | string $cols = self::SQL_WILDCARD, string $schema = null) : \Zend_Db_Select
inherited

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

Inherited from: \Zend_Db_Select::joinRight()

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.

Parameters
Name Type Description
$name array | string | \Zend_Db_Expr

The table name.

$cond string

Join on this condition.

$cols array | string

The columns to select from the joined table.

$schema string

The database name to specify, if any.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpubliclimit(int $count = null, int $offset = null) : \Zend_Db_Select
inherited

Sets a limit count and offset to the query.

Inherited from: \Zend_Db_Select::limit()
Parameters
Name Type Description
$count int

OPTIONAL The number of rows to return.

$offset int

OPTIONAL Start returning after this many rows.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpubliclimitPage(int $page, int $rowCount) : \Zend_Db_Select
inherited

Sets the limit and count by page number.

Inherited from: \Zend_Db_Select::limitPage()
Parameters
Name Type Description
$page int

Limit results to this page number.

$rowCount int

Use this many rows per page.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicorHaving(string $cond, mixed $value = null, int $type = null) : \Zend_Db_Select
inherited

Adds a HAVING condition to the query by OR.

Inherited from: \Zend_Db_Select::orHaving()

Otherwise identical to orHaving().

Parameters
Name Type Description
$cond string

The HAVING condition.

$value mixed

OPTIONAL The value to quote into the condition.

$type int

OPTIONAL The type of the given value

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
Details
See
\global\having()  
methodpublicorWhere(string $cond, mixed $value = null, int $type = null) : \Zend_Db_Select
inherited

Adds a WHERE condition to the query by OR.

Inherited from: \Zend_Db_Select::orWhere()

Otherwise identical to where().

Parameters
Name Type Description
$cond string

The WHERE condition.

$value mixed

OPTIONAL The value to quote into the condition.

$type int

OPTIONAL The type of the given value

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
Details
See
\global\where()  
methodpublicorder(mixed $spec) : \Zend_Db_Select
inherited

Adds a row order to the query.

Inherited from: \Zend_Db_Select::order()
Parameters
Name Type Description
$spec mixed

The column(s) and direction to order by.

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicquery(integer $fetchMode = null, mixed $bind = array()) : \PDO_Statement | \Zend_Db_Statement
inherited

Executes the current select object and returns the result

Inherited from: \Zend_Db_Select::query()
Parameters
Name Type Description
$fetchMode integer

OPTIONAL

$bind mixed

An array of data to bind to the placeholders.

Returns
Type Description
\PDO_Statement | \Zend_Db_Statement
methodpublicreset(string $part = null) : \Zend_Db_Select
inherited

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

Inherited from: \Zend_Db_Select::reset()
Parameters
Name Type Description
$part string

OPTIONAL

Returns
Type Description
\Zend_Db_Select
methodpublicsetIntegrityCheck( $flag = true) : \Zend_Db_Select

Sets the integrity check flag.

Setting this flag to false skips the checks for table joins, allowing 'hybrid' table rows to be created.

Parameters
Name Type Description
$flag
Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicsetTable( $table) : \Zend_Db_Select

Sets the primary table name and retrieves the table schema.

Parameters
Name Type Description
$table
Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicunion(array $select = array(),  $type = self::SQL_UNION) : \Zend_Db_Select
inherited

Adds a UNION clause to the query.

Inherited from: \Zend_Db_Select::union()

The first parameter has to be an array of Zend_Db_Select or sql query strings.

$sql1 = $db->select();
$sql2 = "SELECT ...";
$select = $db->select()
     ->union(array($sql1, $sql2))
     ->order("id");
Parameters
Name Type Description
$select array

Array of select clauses for the union.

$type
Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
methodpublicwhere(string $cond, mixed $value = null, int $type = null) : \Zend_Db_Select
inherited

Adds a WHERE condition to the query by AND.

Inherited from: \Zend_Db_Select::where()

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.

// simplest but non-secure
$select->where("id = $id");

// secure (ID is quoted but matched anyway)
$select->where('id = ?', $id);

// alternatively, with named binding
$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:

$db->fetchAll($select, array('id' => 5));
Parameters
Name Type Description
$cond string

The WHERE condition.

$value mixed

OPTIONAL The value to quote into the condition.

$type int

OPTIONAL The type of the given value

Returns
Type Description
\Zend_Db_Select This Zend_Db_Select object.
Documentation was generated by phpDocumentor 2.0.0a8.