## Apache Zeta Components Manual :: Docs For Class ezcQuerySubSelect

### Database::ezcQuerySubSelect

### Class ezcQuerySubSelect

This class is used to contain subselects

The ezcSubQuery is used for creating correct subqueries inside ezcQuery object. The class holds a refenence to the ezcQuery object that this sub-query is for, and transfers the bindParam() and bindValue() PDO related calls to it.

Example:

1. <?php
2. $q=ezcDbInstance :: get ()->createSelectQuery();
4. // This will produce the following SQL:
5. // SELECT * FROM Greetings WHERE age > 10 AND user IN ( ( SELECT lastname FROM users ) )
7. // Create a subselect:
8. $q2=$q-> subSelect ();
9. $q2-> select ('lastname')-> from ('users');
11. // Use the created subselect to generate the full SQL:
12. $q-> select ('*')-> from ('Greetings');
13. -> where ($q-> expr ->gt('age',10),
14. $q-> expr ->in('user',$q2) );
16. $stmt=$q-> prepare ();// $stmt is a normal PDOStatement
17. $stmt->execute();
18. ?>

Source for this file: /Database/src/sqlabstraction/query_subselect.php

    ezcQuery
       |
       --ezcQuerySelect
          |
          --ezcQuerySubSelect

Version: | //autogentag//

### Inherited Constants

From ezcQuerySelect:
`ezcQuerySelect::ASC` | Sort the result ascending.
`ezcQuerySelect::DESC` | Sort the result descending.

### Member Variables

protected ezcQuery | `$outerQuery = null` Holds the outer query.

### Inherited Member Variables

From ezcQuerySelect
protected | `ezcQuerySelect::$fromString`
protected | `ezcQuerySelect::$groupString`
protected | `ezcQuerySelect::$havingString`
protected | `ezcQuerySelect::$lastInvokedMethod`
protected | `ezcQuerySelect::$limitString`
protected | `ezcQuerySelect::$orderString`
protected | `ezcQuerySelect::$selectString`
protected | `ezcQuerySelect::$whereString`
From ezcQuery
protected | `ezcQuery::$db`
public | `ezcQuery::$expr`

### Method Summary

public ezcQuerySubSelect | `__construct( $outer )` Constructs a new ezcQuerySubSelect object.
public string | `bindParam( &$param , [ $placeHolder = null] , [ $type = PDO::PARAM_STR] , $param )` Binds the parameter $param to the specified variable name $placeHolder.
public string | `bindValue( $value , [ $placeHolder = null] , [ $type = PDO::PARAM_STR] )` Binds the value $value to the specified variable name $placeHolder.
public string | `getQuery( )` Returns the SQL string for the subselect.
public ezcQuerySubSelect | `subSelect( )` Returns ezcQuerySubSelect of deeper level.
public string | `__toString( )` Returns the SQL string for the subselect.

### Inherited Methods

From ezcQuerySelect
public ezcQuerySelect | `ezcQuerySelect::__construct()` Constructs a new ezcQuery object.
public string | `ezcQuerySelect::alias()` Returns SQL to create an alias
protected ezcQuery | `ezcQuerySelect::doJoin()` Returns the SQL for a join or prepares $fromString for a join.
public ezcQuery | `ezcQuerySelect::from()` Select which tables you want to select from.
public static bool|string | `ezcQuerySelect::getDummyTableName()` Returns dummy table name.
public string | `ezcQuerySelect::getQuery()` Returns the complete select query string.
public ezcQuery | `ezcQuerySelect::groupBy()` Returns SQL that groups the result set by a given column.
public ezcQuery | `ezcQuerySelect::having()` Returns SQL that set having by a given expression.
public ezcQuery | `ezcQuerySelect::innerJoin()` Returns the SQL for an inner join or prepares $fromString for an inner join.
public ezcQuery | `ezcQuerySelect::leftJoin()` Returns the SQL for a left join or prepares $fromString for a left join.
public ezcQuerySelect | `ezcQuerySelect::limit()` Returns SQL that limits the result set.
public ezcQuery | `ezcQuerySelect::orderBy()` Returns SQL that orders the result set by a given column.
public void | `ezcQuerySelect::reset()` Resets the query object for reuse.
public ezcQuery | `ezcQuerySelect::rightJoin()` Returns the SQL for a right join or prepares $fromString for a right join.
public ezcQuery | `ezcQuerySelect::select()` Opens the query and selects which columns you want to return with the query.
public ezcQuery | `ezcQuerySelect::selectDistinct()` Opens the query and uses a distinct select on the columns you want to return with the query.
public ezcQuerySelect | `ezcQuerySelect::where()` Adds a where clause with logical expressions to the query.
From ezcQuery
public ezcQuery | `ezcQuery::__construct()` Constructs a new ezcQuery that works on the database $db and with the aliases $aliases.
public static array | `ezcQuery::arrayFlatten()` Returns all the elements in $array as one large single dimensional array.
public string | `ezcQuery::bindParam()` Binds the parameter $param to the specified variable name $placeHolder..
public string | `ezcQuery::bindValue()` Binds the value $value to the specified variable name $placeHolder.
public void | `ezcQuery::doBind()` Performs binding of variables bound with bindValue and bindParam on the statement $stmt.
protected string | `ezcQuery::getIdentifier()` Returns the correct identifier for the alias $alias.
protected array(string) | `ezcQuery::getIdentifiers()` Returns the correct identifiers for the aliases found in $aliases.
public abstract string | `ezcQuery::getQuery()` Returns the query string for this query object.
public bool | `ezcQuery::hasAliases()` Returns true if this object has aliases.
public PDOStatement | `ezcQuery::prepare()` Returns a prepared statement from this query which can be used for execution.
protected void | `ezcQuery::resetBinds()` Resets the bound values and parameters to empty.
public void | `ezcQuery::setAliases()` Sets the aliases $aliases for this object.
public ezcQuerySubSelect | `ezcQuery::subSelect()` Returns the ezcQuerySubSelect query object.
public string | `ezcQuery::__toString()` Return SQL string for query.

### Methods

#### __construct

ezcQuerySubSelect __construct( ezcQuery $outer )

Constructs a new ezcQuerySubSelect object.

The subSelect() method of the ezcQuery object creates an object of this class, and passes itself as $outer parameter to this constructor.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$outer` | ezcQuery |

##### Redefinition of:

Method | Description
--- | ---
`ezcQuerySelect::__construct()` | Constructs a new ezcQuery object.

#### bindParam

string bindParam( &$param , [string $placeHolder = null] , [ $type = PDO::PARAM_STR] , &mixed $param )

Binds the parameter $param to the specified variable name $placeHolder.

This method uses ezcQuery::bindParam() from the ezcQuery class in which the subSelect was called. Info about bound parameters are stored in the parent ezcQuery object that is stored in the $outer property.

The parameter $param specifies the variable that you want to bind. If $placeholder is not provided bind() will automatically create a placeholder for you. An automatic placeholder will be of the name 'ezcValue1', 'ezcValue2' etc.

Example:

1. <?php
2. $value=2;
3. $subSelect=$q-> subSelect ();
4. $subSelect-> select ('*')
5. -> from ('table2')
6. -> where ($subSelect-> expr ->in(
7. 'id',$subSelect-> bindParam ($value)
8. )
9. );
11. $q-> select ('*')
12. -> from ('table')
13. -> where ($q-> expr ->eq('id',$subSelect) );
15. $stmt=$q-> prepare ();// the parameter $value is bound to the query.
16. $value=4;
17. $stmt->execute();// subselect executed with 'id = 4'
18. ?>

##### Parameters:

Name | Type | Description
--- | --- | ---
`$param` | &mixed |
`$placeHolder` | string | the name to bind with. The string must start with a colon ':'.
`&$param` |  |
`$type` |  |

##### Redefinition of:

Method | Description
--- | ---
`ezcQuery::bindParam()` | Binds the parameter $param to the specified variable name $placeHolder..

#### bindValue

string bindValue( mixed $value , [string $placeHolder = null] , [ $type = PDO::PARAM_STR] )

Binds the value $value to the specified variable name $placeHolder.

This method uses ezcQuery::bindParam() from the ezcQuery class in which the subSelect was called. Info about bound parameters are stored in the parent ezcQuery object that is stored in the $outer property.

The parameter $value specifies the value that you want to bind. If $placeholder is not provided bindValue() will automatically create a placeholder for you. An automatic placeholder will be of the name 'ezcValue1', 'ezcValue2' etc.

Example:

1. <?php
2. $value=2;
3. $subSelect=$q-> subSelect ();
4. $subSelect-> select (name)
5. -> from ('table2')
6. -> where ($subSelect-> expr ->in(
7. 'id',$subSelect-> bindValue ($value)
8. )
9. );
11. $q-> select ('*')
12. -> from ('table1')
13. -> where ($q-> expr ->eq('name',$subSelect) );
15. $stmt=$q-> prepare ();// the $value is bound to the query.
16. $value=4;
17. $stmt->execute();// subselect executed with 'id = 2'
18. ?>

##### Parameters:

Name | Type | Description
--- | --- | ---
`$value` | mixed |
`$placeHolder` | string | the name to bind with. The string must start with a colon ':'.
`$type` |  |

##### Redefinition of:

Method | Description
--- | ---
`ezcQuery::bindValue()` | Binds the value $value to the specified variable name $placeHolder.

#### getQuery

string getQuery( )

Returns the SQL string for the subselect.

Example:

1. <?php
2. $subSelect=$q-> subSelect ();
3. $subSelect-> select (name)-> from ('table2');
4. $q-> select ('*')
5. -> from ('table1')
6. -> where ($q-> expr ->eq('name',$subSelect) );
7. $stmt=$q-> prepare ();
8. $stmt->execute();
9. ?>

##### Redefinition of:

Method | Description
--- | ---
`ezcQuerySelect::getQuery()` | Returns the complete select query string.

#### subSelect

ezcQuerySubSelect subSelect( )

Returns ezcQuerySubSelect of deeper level.

Used for making subselects inside subselects.

Example:

1. <?php
2. $value=2;
3. $subSelect=$q-> subSelect ();
4. $subSelect-> select (name)
5. -> from ('table2')
6. -> where ($subSelect-> expr ->in(
7. 'id',$subSelect-> bindValue ($value)
8. )
9. );
11. $q-> select ('*')
12. -> from ('table1')
13. -> where ($q-> expr ->eq('name',$subSelect) );
15. $stmt=$q-> prepare ();// the $value is bound to the query.
16. $value=4;
17. $stmt->execute();// subselect executed with 'id = 2'
18. ?>

##### Redefinition of:

Method | Description
--- | ---
`ezcQuery::subSelect()` | Returns the ezcQuerySubSelect query object.

#### __toString

string __toString( )

Returns the SQL string for the subselect.

Example:

1. <?php
2. $subSelect=$q-> subSelect ();
3. $subSelect-> select (name)-> from ('table2');
4. $q-> select ('*')
5. -> from ('table1')
6. -> where ($q-> expr ->eq('name',$subSelect) );
7. $stmt=$q-> prepare ();
8. $stmt->execute();
9. ?>

##### Redefinition of:

Method | Description
--- | ---
`ezcQuery::__toString()` | Return SQL string for query.

Documentation generated by phpDocumentor 1.4.3