QB
in component
Query Builder. Builds SQL SELECT queries from parts.
Table of Contents
Properties
Methods
- __construct() : mixed
- Creates the query builder using the database object from the registry.
- from() : QB
- Adds a table to the FROM clause.
- getSql() : string
- Builds the SQL query from the collected parts.
- groupBy() : QB
- Adds a GROUP BY expression.
- innerJoin() : QB
- Adds an INNER JOIN.
- leftJoin() : QB
- Adds a LEFT JOIN.
- limit() : QB
- Sets the LIMIT clause.
- orderBy() : QB
- Adds an ORDER BY expression.
- query() : mixed
- Builds and runs the query.
- select() : QB
- Adds an expression to the SELECT clause and optionally a table to FROM.
- where() : QB
- Adds a WHERE condition. Conditions are joined with AND, the elements of an array condition with OR.
Properties
$from
public
mixed
$from
= array()
$groupBy
public
mixed
$groupBy
= array()
$innerJoin
public
mixed
$innerJoin
= array()
$leftJoin
public
mixed
$leftJoin
= array()
$limit
public
mixed
$limit
= array()
$orderBy
public
mixed
$orderBy
= array()
$select
public
mixed
$select
= array()
$where
public
mixed
$where
= array()
$db
protected
mixed
$db
= null
Methods
__construct()
Creates the query builder using the database object from the registry.
public
__construct() : mixed
from()
Adds a table to the FROM clause.
public
from(mixed $from[, mixed $from_key = '' ]) : QB
$from — table name without DB_PREFIX. $from_key — table alias.
Parameters
- $from : mixed
- $from_key : mixed = ''
Return values
QB —This object.
getSql()
Builds the SQL query from the collected parts.
public
getSql() : string
Return values
string —SQL query.
groupBy()
Adds a GROUP BY expression.
public
groupBy(mixed $groupBy[, mixed $after = '' ]) : QB
$groupBy — group expression. $after — insert after this expression instead of appending.
Parameters
- $groupBy : mixed
- $after : mixed = ''
Return values
QB —This object.
innerJoin()
Adds an INNER JOIN.
public
innerJoin(mixed $from[, mixed $from_key = '' ][, mixed $condition = '' ]) : QB
$from — table name without DB_PREFIX. $from_key — table alias. $condition — ON condition.
Parameters
- $from : mixed
- $from_key : mixed = ''
- $condition : mixed = ''
Return values
QB —This object.
leftJoin()
Adds a LEFT JOIN.
public
leftJoin(mixed $from[, mixed $from_key = '' ][, mixed $condition = '' ]) : QB
$from — table name without DB_PREFIX. $from_key — table alias. $condition — ON condition.
Parameters
- $from : mixed
- $from_key : mixed = ''
- $condition : mixed = ''
Return values
QB —This object.
limit()
Sets the LIMIT clause.
public
limit(mixed $start, mixed $limit) : QB
$start — offset. $limit — number of rows.
Parameters
- $start : mixed
- $limit : mixed
Return values
QB —This object.
orderBy()
Adds an ORDER BY expression.
public
orderBy(mixed $order[, mixed $after = '' ]) : QB
$order — order expression. $after — insert after this expression instead of appending.
Parameters
- $order : mixed
- $after : mixed = ''
Return values
QB —This object.
query()
Builds and runs the query.
public
query() : mixed
Return values
mixed —Result of the database query.
select()
Adds an expression to the SELECT clause and optionally a table to FROM.
public
select(mixed $what[, mixed $from = '' ][, mixed $from_key = '' ]) : QB
$what — field list or expression. $from — table name without DB_PREFIX. $from_key — table alias.
Parameters
- $what : mixed
- $from : mixed = ''
- $from_key : mixed = ''
Return values
QB —This object.
where()
Adds a WHERE condition. Conditions are joined with AND, the elements of an array condition with OR.
public
where(mixed $where[, mixed $value = null ]) : QB
$where — condition string, array of conditions, or a field name when $value is given. $value — value compared with the field; escaped.
Parameters
- $where : mixed
- $value : mixed = null
Return values
QB —This object.