Database: ezcQuerySubSelect
[ ]
[ Oracle setup ]
[ ]
[ ]
[ ]
[ ]
Class: ezcQuerySubSelect
|
This class is used to contain subselects [
source]
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();
3.
4. // This will produce the following SQL:
5. // SELECT * FROM Greetings WHERE age > 10 AND user IN ( ( SELECT lastname FROM users ) )
6.
7. // Create a subselect:
8. $q2 = $q->subSelect();
9. $q2->select( 'lastname' )->from( 'users' );
10.
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 ) );
15.
16. $stmt = $q->prepare(); // $stmt is a normal PDOStatement
17. $stmt->execute();
18. ?>
Parents
ezcQuery
|
--ezcQuerySelect
|
--ezcQuerySubSelect
Inherited Constants
From
ezcQuerySelect:
Member Variables
Inherited Member Variables
From
ezcQuerySelect:
From
ezcQuery:
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 :
From
ezcQuery :
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
Redefinition of
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. );
10.
11. $q->select( '*' )
12. ->from( 'table' )
13. ->where ( $q->expr->eq( 'id', $subSelect ) );
14.
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 |
|
|
See also:
ezcQuery::bindParam().
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. );
10.
11. $q->select( '*' )
12. ->from( 'table1' )
13. ->where ( $q->expr->eq( 'name', $subSelect ) );
14.
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 |
|
|
See also:
ezcQuery::bindValue().
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
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. );
10.
11. $q->select( '*' )
12. ->from( 'table1' )
13. ->where ( $q->expr->eq( 'name', $subSelect ) );
14.
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
__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
Last updated: Mon, 27 Jul 2009