framework to construct complex queries in a safer environment. More...
Public Member Functions | |
| __construct () | |
| Construct query & initialise variables. | |
| setLimitAndOffset (LimitOffsetQueryComponent $component) | |
| Add limits and offsets to the query. | |
| setSelectField (SelectFieldQueryComponent $component) | |
| Reset and set the field to the select statement. | |
| addSelectField (SelectFieldQueryComponent $component) | |
| Add a select field. | |
| addJoin (JoinQueryComponent $component) | |
| Add a join to the component. | |
| addSet (SetQueryComponent $component) | |
| Set a field value in an update or insert statement. | |
| setQueryType (QueryTypeQueryComponent $component) | |
| Set the query type, i.e. | |
| setOrder (OrderQueryComponent $component) | |
| Attach an order component. | |
| addTable (TableQueryComponent $component) | |
| Add a table to the query. | |
| addWhere (WhereQueryComponent $component) | |
| Add a where clause to the query. | |
| setAccessControl (AccessControlQueryComponent $component) | |
| Set access control. | |
| __toString () | |
framework to construct complex queries in a safer environment.
The usage of this class depends on the type of query you are executing, but the basic idea is to construct a query out of pluggable classes.
Once constructed SQL can be generated using the toString method, this should happen automatically if you pass the Query object to get_data or similar.
To construct a query, create a new Query() object and begin populating it with the various classes that define the various aspects of the query.
Notes:
With database tables you do not have to specify your db prefix, this will be added automatically.
Here is an example of a select query which requests some data out of the entities table with an order and limit that uses a subset where and some normal where queries:
<blockquote> // Construct the query $query = new Query();
// Say which table we're interested in $query->addTable(new TableQueryComponent("entities"));
// What fields are we interested in $query->addSelectField(new SelectFieldQueryComponent("entities","*"));
// Add access control (Default access control uses default fields on entities table. // Note that it will error without something specified here! $query->setAccessControl(new AccessControlQueryComponent());
// Set a limit and offset, may be omitted. $query->setLimitAndOffset(new LimitOffsetQueryComponent(10,0));
// Specify the order, may be omitted $query->setOrder(new OrderQueryComponent("entities", "subtype", "desc"));
// Construct a where query // // This demonstrates a WhereSet which lets you have sub wheres, a // WhereStatic which lets you compare a table field against a value and a // Where which lets you compare a table/field with another table/field. $query->addWhere( new WhereSetQueryComponent( array( new WhereStaticQueryComponent("entities", "subtype","=", 1), new WhereQueryComponent("entities","subtype","=", "entities", "subtype") ) ) );
get_data($query); </blockquote>
Definition at line 516 of file query.php.
| Query::__construct | ( | ) |
Construct query & initialise variables.
Reimplemented in SimpleQuery.
| Query::addJoin | ( | JoinQueryComponent $ | component | ) |
Add a join to the component.
| JoinQueryComponent | $component The join. |
| Query::addSelectField | ( | SelectFieldQueryComponent $ | component | ) |
Add a select field.
| SelectFieldQueryComponent | $component Add a component. |
| Query::addSet | ( | SetQueryComponent $ | component | ) |
Set a field value in an update or insert statement.
| SetQueryComponent | $component Fields to set. |
| Query::addTable | ( | TableQueryComponent $ | component | ) |
Add a table to the query.
| TableQueryComponent | $component Table to add. |
| Query::addWhere | ( | WhereQueryComponent $ | component | ) |
Add a where clause to the query.
| WhereQueryComponent | $component The where component |
| Query::setAccessControl | ( | AccessControlQueryComponent $ | component | ) |
Set access control.
| AccessControlQueryComponent | $component Access control. |
| Query::setLimitAndOffset | ( | LimitOffsetQueryComponent $ | component | ) |
Add limits and offsets to the query.
| LimitOffsetQueryComponent | $component The limit and offset. |
| Query::setOrder | ( | OrderQueryComponent $ | component | ) |
Attach an order component.
| OrderQueryComponent | $component The order component. |
| Query::setQueryType | ( | QueryTypeQueryComponent $ | component | ) |
Set the query type, i.e.
"select", "update", "insert" & "delete".
| QueryTypeQueryComponent | $component The query type. |
| Query::setSelectField | ( | SelectFieldQueryComponent $ | component | ) |
Reset and set the field to the select statement.
| SelectFieldQueryComponent | $component Table and field component. |
1.6.3