core/xpdo/om/mysql/xpdoquery.class.php
The MySQL implementation of xPDOQuery.
- Package
- xpdo
- Subpackage
- om.mysql
\xPDOQuery_mysql
An implementation of xPDOQuery for the MySQL database engine.
- Parent(s)
- \xPDOQuery < \xPDOCriteria
Constants
SQL_JOIN_CROSS
= 'JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_CROSS
SQL_JOIN_LEFT
= 'LEFT JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_LEFT
SQL_JOIN_RIGHT
= 'RIGHT JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_RIGHT
SQL_JOIN_NATURAL_LEFT
= 'NATURAL LEFT JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_NATURAL_LEFT
SQL_JOIN_NATURAL_RIGHT
= 'NATURAL RIGHT JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_NATURAL_RIGHT
SQL_JOIN_STRAIGHT
= 'STRAIGHT_JOIN'
- Inherited_from
- \xPDOQuery::SQL_JOIN_STRAIGHT
Properties
$_alias= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$_alias
$_class= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$_class
array
$_operators= 'array (
'=',
'!=',
'<',
'<=',
'>',
'>=',
'<=>',
' LIKE ',
' IS NULL',
' IS NOT NULL',
' BETWEEN ',
' IN ',
' IN(',
' NOT(',
' NOT (',
' NOT IN ',
' NOT IN(',
' EXISTS (',
' EXISTS(',
' NOT EXISTS (',
' NOT EXISTS(',
' COALESCE(',
' GREATEST(',
' INTERVAL(',
' LEAST(',
'MATCH(',
'MATCH ('
)'
An array of symbols and keywords indicative of SQL operators.
Inherited from: \xPDOQuery::$$_operatorsarray (
'=',
'!=',
'<',
'<=',
'>',
'>=',
'<=>',
' LIKE ',
' IS NULL',
' IS NOT NULL',
' BETWEEN ',
' IN ',
' IN(',
' NOT(',
' NOT (',
' NOT IN ',
' NOT IN(',
' EXISTS (',
' EXISTS(',
' NOT EXISTS (',
' NOT EXISTS(',
' COALESCE(',
' GREATEST(',
' INTERVAL(',
' LEAST(',
'MATCH(',
'MATCH ('
)
Details- Type
- array
- Inherited_from
- \xPDOQuery::$$_operators
$_quotable= 'array ('string', 'password', 'date', 'datetime', 'timestamp', 'time')'
array ('string', 'password', 'date', 'datetime', 'timestamp', 'time')
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$_quotable
$_tableClass= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$_tableClass
$bindings= 'array ()'
array ()
Details- Type
- n/a
- Inherited_from
- \xPDOCriteria::$$bindings
- Inherited_from
- \xPDOQuery::$$bindings
$cacheFlag= 'false'
false
Details- Type
- n/a
- Inherited_from
- \xPDOCriteria::$$cacheFlag
- Inherited_from
- \xPDOQuery::$$cacheFlag
$graph= 'array ()'
array ()
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$graph
$query= 'array (
'command' => 'SELECT',
'distinct' => '',
'columns' => '',
'from' => array (
'tables' => array (),
'joins' => array (),
),
'set' => array (),
'where' => array (),
'groupby' => array (),
'having' => array (),
'orderby' => array (),
'offset' => '',
'limit' => '',
)'
array (
'command' => 'SELECT',
'distinct' => '',
'columns' => '',
'from' => array (
'tables' => array (),
'joins' => array (),
),
'set' => array (),
'where' => array (),
'groupby' => array (),
'having' => array (),
'orderby' => array (),
'offset' => '',
'limit' => '',
)
Details- Type
- n/a
- Inherited_from
- \xPDOQuery::$$query
$sql= ''''
''
Details- Type
- n/a
- Inherited_from
- \xPDOCriteria::$$sql
- Inherited_from
- \xPDOQuery::$$sql
$stmt= 'null'
null
Details- Type
- n/a
- Inherited_from
- \xPDOCriteria::$$stmt
- Inherited_from
- \xPDOQuery::$$stmt
Methods
__construct(
\xPDO $xpdo, $class, $criteria
=
null
)
:
\xPDOCriteria
The constructor for a new xPDOCriteria instance.
The constructor optionally prepares provided SQL and/or parameter bindings. Setting the bindings via the constructor or with the {@link xPDOCriteria::bind()} function allows you to make use of the data object caching layer.
The statement will not be prepared immediately if the cacheFlag value is true or a positive integer, in order to allow the result to be found in the cache before being queried from an actual database connection.
Name | Type | Description |
---|---|---|
$xpdo | \xPDO | &$xpdo An xPDO instance that will control this criteria. |
$class | ||
$criteria |
Type | Description |
---|---|
\xPDOCriteria |
andCondition(
$conditions, $binding
=
null, $group
=
0
)
:
void
Name | Type | Description |
---|---|---|
$conditions | ||
$binding | ||
$group |
bind(
array $bindings
=
array (), boolean $byValue
=
true, boolean | integer $cacheFlag
=
false
)
:
void
Binds an array of key/value pairs to the xPDOCriteria prepared statement.
Inherited from: \xPDOCriteria::bind()\xPDOQuery::bind()Use this method to bind parameters in a way that makes it possible to cache results of previous executions of the criteria or compare the criteria to other individual or collections of criteria.
Name | Type | Description |
---|---|---|
$bindings | array | Bindings to merge with any existing bindings defined for this xPDOCriteria instance. Bindings can be simple associative array of key-value pairs or the value for each key can contain elements titled value, type, and length corresponding to the appropriate parameters in the PDOStatement::bindValue() and PDOStatement::bindParam() functions. |
$byValue | boolean | Determines if the $bindings are to be bound as parameters (by variable reference, the default behavior) or by direct value (if true). |
$cacheFlag | boolean | integer | The cacheFlag indicates the cache state of the xPDOCriteria object and can be absolutely off (false), absolutely on (true), or an integer indicating the number of seconds the result will live in the cache. |
bindGraph(
mixed $graph
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$graph | mixed | An array or JSON graph of related objects. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
bindGraphNode(
string $parentClass, string $parentAlias, string $classAlias, array $relations
)
:
void
Name | Type | Description |
---|---|---|
$parentClass | string | The class representing the relation parent. |
$parentAlias | string | The alias the class is assuming. |
$classAlias | string | The class representing the related graph node. |
$relations | array | Child relations of the current graph node. |
buildConditionalClause(
array | \xPDOQueryCondition $conditions, string $conjunction
=
xPDOQuery::SQL_AND, boolean $isFirst
=
true
)
:
string
Builds conditional clauses from xPDO condition expressions.
Inherited from: \xPDOQuery::buildConditionalClause()Name | Type | Description |
---|---|---|
$conditions | array | \xPDOQueryCondition | An array of conditions or an xPDOQueryCondition instance. |
$conjunction | string | Either xPDOQuery:SQL_AND or xPDOQuery::SQL_OR |
$isFirst | boolean | Indicates if this is the first condition in an array. |
Type | Description |
---|---|
string | The generated SQL clause. |
command(
string $command
=
'SELECT'
)
:
\xPDOQuery
The default is SELECT, though it also supports DELETE and UPDATE.
Name | Type | Description |
---|---|---|
$command | string | The type of SQL statement represented by this object. Default is 'SELECT'. |
Type | Description |
---|---|
\xPDOQuery | Returns the current object for convenience. |
condition(
string $target, mixed $conditions
=
'1', string $conjunction
=
xPDOQuery::SQL_AND, mixed $binding
=
null, integer $condGroup
=
0
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$target | string | The target clause for the condition. |
$conditions | mixed | A valid xPDO criteria expression. |
$conjunction | string | The conjunction to use when appending this condition, i.e., AND or OR. |
$binding | mixed | A value or PDO binding representation of a value for the condition. |
$condGroup | integer | A numeric identifier for associating conditions into groups. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
construct(
)
:
boolean
Constructs the SQL query from the xPDOQuery definition.
Type | Description |
---|---|
boolean | Returns true if a SQL statement was successfully constructed. |
distinct(
null | boolean $on
=
null
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$on | null | boolean | Defines how to set the distinct attribute: - null (default) indicates the distinct attribute should be toggled - any other value is treated as a boolean, i.e. true to set DISTINCT, false to unset |
Type | Description |
---|---|
\xPDOQuery | Returns the current object for convenience. |
equals(
object $obj
)
:
boolean
Compares to see if two xPDOCriteria instances are the same.
Inherited from: \xPDOCriteria::equals()\xPDOQuery::equals()Name | Type | Description |
---|---|---|
$obj | object | A xPDOCriteria object to compare to this one. |
Type | Description |
---|---|
boolean | true if they are both equal is SQL and bindings, otherwise false. |
from(
string $class, string $alias
=
''
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$class | string | The class representing the table to add. |
$alias | string | An optional alias for the class. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
groupby(
string $column, string $direction
=
''
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$column | string | Column identifier to group by. |
$direction | string | The direction to sort by, ASC or DESC. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
having(
$conditions
)
:
void
Name | Type | Description |
---|---|---|
$conditions |
hydrateGraph(
array $rows, $cacheFlag
=
true
)
:
array
Hydrates a graph of related objects from a single result set.
Inherited from: \xPDOQuery::hydrateGraph()Name | Type | Description |
---|---|---|
$rows | array | A collection of result set rows for hydrating the graph. |
$cacheFlag |
Type | Description |
---|---|
array | A collection of objects with all related objects from the graph pre-populated. |
hydrateGraphNode(
array $row, \xPDOObject $instance, string $alias, array $relations
)
:
void
Name | Type | Description |
---|---|---|
$row | array | The result set representing the current node. |
$instance | \xPDOObject | The xPDOObject instance to be hydrated from the node. |
$alias | string | The alias identifying the object in the parent relationship. |
$relations | array | Child relations of the current node. |
hydrateGraphParent(
$instances, $row
)
:
void
Name | Type | Description |
---|---|---|
$instances | ||
$row |
innerJoin(
$class, $alias
=
'', $conditions
=
array (), $conjunction
=
xPDOQuery::SQL_AND, $binding
=
null, $condGroup
=
0
)
:
void
Name | Type | Description |
---|---|---|
$class | ||
$alias | ||
$conditions | ||
$conjunction | ||
$binding | ||
$condGroup |
isConditionalClause(
string $string
)
:
boolean
Determines if a string contains a conditional operator.
Inherited from: \xPDOQuery::isConditionalClause()Name | Type | Description |
---|---|---|
$string | string | The string to evaluate. |
Type | Description |
---|---|
boolean | True if the string is a complete conditional SQL clause. |
join(
string $class, string $alias
=
'', string $type
=
xPDOQuery::SQL_JOIN_CROSS, mixed $conditions
=
array (), string $conjunction
=
xPDOQuery::SQL_AND, array $binding
=
null, int $condGroup
=
0
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$class | string | The classname (or relation alias for aggregates and composites) of representing the table to be joined. |
$alias | string | An optional alias to represent the joined table in the constructed query. |
$type | string | The type of join to perform. See the xPDOQuery::SQL_JOIN constants. |
$conditions | mixed | Conditions of the join specified in any xPDO compatible criteria object or expression. |
$conjunction | string | A conjunction to be applied to the condition or conditions supplied. |
$binding | array | Optional bindings to accompany the conditions. |
$condGroup | int | An optional identifier for adding the conditions to a specific set of conjoined expressions. |
Type | Description |
---|---|
\xPDOQuery | Returns the current object for convenience. |
leftJoin(
$class, $alias
=
'', $conditions
=
array (), $conjunction
=
xPDOQuery::SQL_AND, $binding
=
null, $condGroup
=
0
)
:
void
Name | Type | Description |
---|---|---|
$class | ||
$alias | ||
$conditions | ||
$conjunction | ||
$binding | ||
$condGroup |
limit(
integer $limit, integer $offset
=
0
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$limit | integer | The number of records to return. |
$offset | integer | The location in the result set to start from. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
orCondition(
$conditions, $binding
=
null, $group
=
0
)
:
void
Name | Type | Description |
---|---|---|
$conditions | ||
$binding | ||
$group |
parseConditions(
mixed $conditions, string $conjunction
=
xPDOQuery::SQL_AND
)
:
void
Name | Type | Description |
---|---|---|
$conditions | mixed | A valid xPDO condition expression. |
$conjunction | string | The optional conjunction for the condition( s ). |
prepare(
array $bindings
=
array (), boolean $byValue
=
true, boolean | integer $cacheFlag
=
null
)
:
\PDOStatement
The {@link xPDOCriteria::$sql} attribute must be set in order to prepare the statement. You can also pass bindings directly to this function and they will be run through {@link xPDOCriteria::bind()} if the statement is successfully prepared.
If the {@link xPDOCriteria::$stmt} already exists, it is simply returned.
Name | Type | Description |
---|---|---|
$bindings | array | Bindings to merge with any existing bindings defined for this xPDOCriteria instance. Bindings can be simple associative array of key-value pairs or the value for each key can contain elements titled value, type, and length corresponding to the appropriate parameters in the PDOStatement::bindValue() and PDOStatement::bindParam() functions. |
$byValue | boolean | Determines if the $bindings are to be bound as parameters (by variable reference, the default behavior) or by direct value (if true). |
$cacheFlag | boolean | integer | The cacheFlag indicates the cache state of the xPDOCriteria object and can be absolutely off (false), absolutely on (true), or an integer indicating the number of seconds the result will live in the cache. |
Type | Description |
---|---|
\PDOStatement | The PDOStatement representing the prepared query. |
rightJoin(
$class, $alias
=
'', $conditions
=
array (), $conjunction
=
xPDOQuery::SQL_AND, $binding
=
null, $condGroup
=
0
)
:
void
Name | Type | Description |
---|---|---|
$class | ||
$alias | ||
$conditions | ||
$conjunction | ||
$binding | ||
$condGroup |
select(
string $columns
=
'*'
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$columns | string | Columns to return from the query. |
Type | Description |
---|---|
\xPDOQuery | Returns the current object for convenience. |
set(
array $values
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$values | array | An associative array of fields and the values to set them to. |
Type | Description |
---|---|
\xPDOQuery | Returns a reference to the current instance for convenience. |
setClassAlias(
string $alias
=
''
)
:
\xPDOQuery
Sets a SQL alias for the table represented by the main class.
Inherited from: \xPDOQuery::setClassAlias()Name | Type | Description |
---|---|---|
$alias | string | An alias for the main table for the SQL statement. |
Type | Description |
---|---|
\xPDOQuery | Returns the current object for convenience. |
sortby(
string $column, string $direction
=
'ASC'
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$column | string | Column identifier to sort by. |
$direction | string | The direction to sort by, ASC or DESC. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
toSQL(
)
:
string
Converts the current xPDOQuery to parsed SQL.
Inherited from: \xPDOCriteria::toSQL()\xPDOQuery::toSQL()Type | Description |
---|---|
string | The parsed SQL query. |
- Access
- public
where(
mixed $conditions
=
'', string $conjunction
=
xPDOQuery::SQL_AND, mixed $binding
=
null, integer $condGroup
=
0
)
:
\xPDOQuery
Name | Type | Description |
---|---|---|
$conditions | mixed | A valid xPDO criteria expression. |
$conjunction | string | The conjunction to use when appending this condition, i.e., AND or OR. |
$binding | mixed | A value or PDO binding representation of a value for the condition. |
$condGroup | integer | A numeric identifier for associating conditions into groups. |
Type | Description |
---|---|
\xPDOQuery | Returns the instance. |
wrap(
\xPDOCriteria $criteria
)
:
void
Wrap an existing xPDOCriteria into this xPDOQuery instance.
Inherited from: \xPDOQuery::wrap()Name | Type | Description |
---|---|---|
$criteria | \xPDOCriteria |