The ezcQuery class provides the common API for all Query objects.
ezcQuery has three main purposes:
Subclasses should provide functionality to build an actual query.
Source for this file: /Database/src/sqlabstraction/query.php
Version: | //autogentag// |
Child Class | Description |
---|---|
ezcQueryInsert | Class to create select database independent INSERT queries. |
ezcQuerySelect | Class to create select database independent SELECT queries. |
ezcQueryUpdate | Class to create select database independent UPDATE queries. |
ezcQueryDelete | Class to create select database independent DELETE queries. |
protected PDO |
$db
A pointer to the database handler to use for this query. |
public ezcQueryExpression |
$expr
= null
The expression object for this class. |
public static array |
arrayFlatten(
$array
)
Returns all the elements in $array as one large single dimensional array. |
public ezcQuery |
__construct(
$db
, [ $aliases
= array()] )
Constructs a new ezcQuery that works on the database $db and with the aliases $aliases. |
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 void |
doBind(
$stmt
)
Performs binding of variables bound with bindValue and bindParam on the statement $stmt. |
protected string |
getIdentifier(
$alias
)
Returns the correct identifier for the alias $alias. |
protected array(string) |
getIdentifiers(
$aliasList
)
Returns the correct identifiers for the aliases found in $aliases. |
public abstract string |
getQuery(
)
Returns the query string for this query object. |
public bool |
hasAliases(
)
Returns true if this object has aliases. |
public PDOStatement |
prepare(
)
Returns a prepared statement from this query which can be used for execution. |
protected void |
resetBinds(
)
Resets the bound values and parameters to empty. |
public void |
setAliases(
$aliases
)
Sets the aliases $aliases for this object. |
public ezcQuerySubSelect |
subSelect(
)
Returns the ezcQuerySubSelect query object. |
public string |
__toString(
)
Return SQL string for query. |
Returns all the elements in $array as one large single dimensional array.
Name | Type | Description |
---|---|---|
$array |
array |
Constructs a new ezcQuery that works on the database $db and with the aliases $aliases.
The aliases can be used to substitute the column and table names with more friendly names. E.g PersistentObject uses it to allow using property and class names instead of column and table names.
Name | Type | Description |
---|---|---|
$db |
PDO | |
$aliases |
array(string=>string) |
Method | Description |
---|---|
ezcQueryInsert::__construct() |
Constructs a new ezcQueryInsert that works on the database $db and with the aliases $aliases. |
ezcQuerySelect::__construct() |
Constructs a new ezcQuery object. |
ezcQuerySelectSqlite::__construct() |
Constructs a new ezcQuerySelectSqlite object. |
ezcQuerySelectOracle::__construct() |
Constructs a new ezcQueryOracle object working on the database $db. |
ezcQuerySubSelect::__construct() |
Constructs a new ezcQuerySubSelect object. |
ezcQueryUpdate::__construct() |
Constructs a new ezcQueryUpdate that works on the database $db and with the aliases $aliases. |
ezcQueryDelete::__construct() |
Constructs a new ezcQueryDelete that works on the database $db and with the aliases $aliases. |
Binds the parameter $param to the specified variable name $placeHolder..
This method provides a shortcut for PDOStatement::bindParam when using prepared statements.
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.
For more information see http://php.net/pdostatement-bindparam
Example:
Name | Type | Description |
---|---|---|
$param |
&mixed | |
$placeHolder |
string | the name to bind with. The string must start with a colon ':'. |
&$param |
||
$type |
Method | Description |
---|---|
ezcQuerySubSelect::bindParam() |
Binds the parameter $param to the specified variable name $placeHolder. |
Binds the value $value to the specified variable name $placeHolder.
This method provides a shortcut for PDOStatement::bindValue when using prepared statements.
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.
For more information see http://php.net/pdostatement-bindparam
Example:
Name | Type | Description |
---|---|---|
$value |
mixed | |
$placeHolder |
string | the name to bind with. The string must start with a colon ':'. |
$type |
Method | Description |
---|---|
ezcQuerySubSelect::bindValue() |
Binds the value $value to the specified variable name $placeHolder. |
Performs binding of variables bound with bindValue and bindParam on the statement $stmt.
This method must be called if you have used the bind methods in your query and you build the method yourself using build.
Name | Type | Description |
---|---|---|
$stmt |
PDOStatement |
Returns the correct identifier for the alias $alias.
If the alias does not exists in the list of aliases it is returned unchanged.
This can method handles composite identifiers separated by a dot ('.').
Name | Type | Description |
---|---|---|
$alias |
string |
Returns the correct identifiers for the aliases found in $aliases.
This method is similar to getIdentifier except that it works on an array.
Name | Type | Description |
---|---|---|
$aliasList |
array(string) |
Returns the query string for this query object.
Type | Description |
---|---|
ezcQueryInvalidException |
if it was not possible to build a valid query. |
Method | Description |
---|---|
ezcQueryInsert::getQuery() |
Returns the query string for this query object. |
ezcQuerySelect::getQuery() |
Returns the complete select query string. |
ezcQuerySelectMssql::getQuery() |
Transforms the query from the parent to provide LIMIT functionality. |
ezcQuerySelectOracle::getQuery() |
Transforms the query from the parent to provide LIMIT functionality. |
ezcQuerySubSelect::getQuery() |
Returns the SQL string for the subselect. |
ezcQueryUpdate::getQuery() |
Returns the query string for this query object. |
ezcQueryDelete::getQuery() |
Returns the query string for this query object. |
Returns true if this object has aliases.
Returns a prepared statement from this query which can be used for execution.
The returned object is a PDOStatement for which you can find extensive documentation in the PHP manual: http://php.net/pdostatement-bindcolumn
prepare() automatically calls doBind() on the statement.
Method | Description |
---|---|
ezcQuerySelectOracle::prepare() |
Handles preparing query. |
Resets the bound values and parameters to empty.
This is useful if your query can be reset and used multiple times.
Sets the aliases $aliases for this object.
The aliases should be in the form array( "aliasName" => "databaseName" ) Each alias defines a relation between a user-defined name and a name in the database. This is supported for table names as column names.
The aliases can be used to substitute the column and table names with more friendly names. The substitution is done when the query is built, not using AS statements in the database itself.
Example of a select query with aliases:
This example will output SQL similar to:
Aliasses also take effect for composite names in the form tablename.columnname as the following example shows:
This example will output SQL similar to:
It is even possible to have an alias point to a table name/column name combination. This will only work for alias names without a . (dot):
This example will output SQL similar to:
In the following example, the Recipient alias will not be used, as it is points to a fully qualified name - the Order alias however is used:
This example will output SQL similar to:
Name | Type | Description |
---|---|---|
$aliases |
array(string=>string) |
Returns the ezcQuerySubSelect query object.
This method creates new ezcQuerySubSelect object that could be used for building correct subselect inside query.
Method | Description |
---|---|
ezcQuerySubSelect::subSelect() |
Returns ezcQuerySubSelect of deeper level. |
Return SQL string for query.
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:
Method | Description |
---|---|
ezcQuerySubSelect::__toString() |
Returns the SQL string for the subselect. |