Database: ezcQuerySubSelect
[ ]
[ Oracle setup ]
[ ]
[ ]
[ ]
[ ]
Class: ezcQuerySubSelect
|
Class to create subselects within queries. [
source]
The ezcSubQuery used for creating correct subqueries inside ezcQuery object. Class holds a refenence to inclusive ezcQuery and transfer PDO related calls to it.
Example:
1. $q = ezcDbInstance::get()->createSelectQuery();
2. $q2 = $q->subSelect();
3.
4. $q2->select( 'lastname' )->from( 'users' );
5.
6. // This will produce SQL:
7. // SELECT * FROM Greetings WHERE age > 10 AND user IN ( ( SELECT lastname FROM users ) )
8. $q->select( '*' )->from( 'Greetings' );
9. ->where( $q->expr->gt( 'age', 10 ),
10. $q->expr->in( 'user', $q2 ) );
11.
12. $stmt = $q->prepare(); // $stmt is a normal PDOStatement
13. $stmt->execute();
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 ezcQuery 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(
)
Return string with SQL query for subselect. |
|
public ezcQuerySubSelect |
subSelect(
)
Returns ezcQuerySubSelect of deeper level. |
|
public string |
__toString(
)
Return SQL string for subselect. |
Inherited Methods
From
ezcQuerySelect :
From
ezcQuery :
Methods
__construct
ezcQuerySubSelect __construct(
ezcQuery
$outer )
Constructs a new ezcQuery object.
Parameters
| Name |
Type |
Description |
$outer |
ezcQuery |
reference to inclusive ezcQuery object. |
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 use ezcQuery::bindParam() from the ezcQuery in which subselect included. Info about bounded parameters stored in ezcQuery.
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. $value = 2;
2. $subSelect = $q->subSelect();
3. $subSelect->select('*')
4. ->from( 'table2' )
5. ->where( $subSelect->expr->in('id', $subSelect->bindParam( $value )) );
6.
7. $q->select('*')
8. ->from( 'table' )
9. ->where ( $q->expr->eq( 'id', $subSelect ) );
10.
11. $stmt = $q->prepare(); // the parameter $value is bound to the query.
12. $value = 4;
12. $stmt->execute(); // subselect executed with 'id = 4'
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 use ezcQuery::bindValue() from the ezcQuery in which subselect included. Info about bounded parameters stored in ezcQuery.
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. $value = 2;
2. $subSelect = $q->subSelect();
3. $subSelect->select( name )
4. ->from( 'table2' )
5. ->where( $subSelect->expr->in('id', $subSelect->bindValue( $value )) );
6.
7. $q->select('*')
8. ->from( 'table1' )
9. ->where ( $q->expr->eq( 'name', $subSelect ) );
10.
11. $stmt = $q->prepare(); // the $value is bound to the query.
12. $value = 4;
12. $stmt->execute(); // subselect executed with 'id = 2'
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(
)
Return string with SQL query for subselect.
Example:
1. $subSelect = $q->subSelect();
2. $subSelect->select( name )->from( 'table2' );
3. $q->select('*')
4. ->from( 'table1' )
5. ->where ( $q->expr->eq( 'name', $subSelect ) );
6. $stmt = $q->prepare();
7. $stmt->execute();
Redefinition of
subSelect
Returns ezcQuerySubSelect of deeper level.
Used for making subselects inside subselects.
Example:
1. $value = 2;
2. $subSelect = $q->subSelect();
3. $subSelect->select( name )
4. ->from( 'table2' )
5. ->where( $subSelect->expr->in('id', $subSelect->bindValue( $value )) );
6.
7. $q->select(*)
8. ->from( 'table1' )
9. ->where ( $q->expr->eq( 'name', $subSelect ) );
10.
11. $stmt = $q->prepare(); // the $value is bound to the query.
12. $value = 4;
12. $stmt->execute(); // subselect executed with 'id = 2'
Redefinition of
__toString
string __toString(
)
Return SQL string for subselect.
Typecasting to (string) should be used to make __toString() to be called with PHP 5.1. This will not be needed in PHP 5.2 and higher when this object is used in a string context.
Example:
1. $subSelect = $q->subSelect();
2. $subSelect->select( name )->from( 'table2' );
3. $q->select('*')
4. ->from( 'table1' )
5. ->where ( $q->expr->eq( 'name', (string)$subSelect ) );
6. $stmt = $q->prepare();
7. $stmt->execute();
Redefinition of
Last updated: Mon, 10 Nov 2008