Methods |
public
|
__construct(string $table = null, string $alias = null): void
Constructor
Parameters
$table |
The base table to select from
|
$alias |
The alias for the table
|
|
#
|
public
|
from(string $table, string $alias = null): object
Table to SELECT
Parameters
$table |
The table name
|
$alias |
The table alias
|
Returns
|
#
|
public
|
fields(string $alias, array $fields = []): object
Add fields to SELECT
Parameters
$alias |
The table alias
|
$fields |
Array of field names
|
Returns
|
#
|
public
|
field(string $field, array $alias = null): object
Add field to SELECT
Parameters
$field |
The field name
|
$alias |
The alias for the field name
|
Returns
|
#
|
public
|
join(string $table, string $alias, string $condition, string $type = 'INNER'): object
Add a table to join
Parameters
$table |
The table name
|
$alias |
The alias for the table
|
$condition |
The join condition e.g., t1.pk = t2.fk
|
$type |
INNER, LEFT, RIGHT or OUTER
|
Returns
|
#
|
public
|
leftJoin(string $table, string $alias, string $condition): object
Add a table to perform left join
Add a table to perform left join
Parameters
$table |
The table name
|
$alias |
The alias for the table
|
$condition |
The join condition e.g., t1.pk = t2.fk
|
Returns
|
#
|
public
|
rightJoin(string $table, string $alias, string $condition): object
Add a table to perform right join
Add a table to perform right join
Parameters
$table |
The table name
|
$alias |
The alias for the table
|
$condition |
The join condition e.g., t1.pk = t2.fk
|
Returns
|
#
|
public
|
outerJoin(string $table, string $alias, string $condition): object
Add a table to perform outer join
Add a table to perform outer join
Parameters
$table |
The table name
|
$alias |
The alias for the table
|
$condition |
The join condition e.g., t1.pk = t2.fk
|
Returns
|
#
|
public
|
where(array|null $condition = null): object
Alias of `andWhere()`
Create WHERE ... AND condition
Alias of andWhere()
Create WHERE ... AND condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
andWhere(array|null $condition = null): object
Create WHERE ... AND condition
Create WHERE ... AND condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
orWhere(array|null $condition = null): object
Create WHERE ... OR condition
Create WHERE ... OR condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
condition(string $field, mixed $value): object
Create simple WHERE condition with field/value assignment
Create simple WHERE condition with field/value assignment
Parameters
$field |
The field name
|
$value |
The value to check against the field name
|
Returns
|
#
|
public
|
exists(string $subquery, string $type = 'AND'): object
Add EXISTS clause to WHERE condition
Add EXISTS clause to WHERE condition
Parameters
$subquery |
The sub-query statement
|
$type |
AND|OR
|
Returns
|
#
|
public
|
notExists(string $subquery, string $type = 'AND'): object
Add NOT EXISTS clause to WHERE condition
Add NOT EXISTS clause to WHERE condition
Parameters
$subquery |
The sub-query statement
|
$type |
AND|OR
|
Returns
|
#
|
public
|
orExists(string $subquery): object
Add `OR EXISTS` clause to WHERE condition
Add OR EXISTS clause to WHERE condition
Parameters
$subquery |
The sub-query statement
|
Returns
|
#
|
public
|
orNotExists(string $subquery): object
Add `OR NOT EXISTS` clause to WHERE condition
Add OR NOT EXISTS clause to WHERE condition
Parameters
$subquery |
The sub-query statement
|
Returns
|
#
|
public
|
orderBy(string $field, string $sort = 'ASC'): object
Add ORDER BY clause
Parameters
$field |
The field name to sort
|
$sort |
ASC or DESC
|
Returns
|
#
|
public
|
groupBy(string $field): object
Add GROUP BY clause
|
#
|
public
|
having(array $condition): object
Create HAVING ... condition
Create HAVING ... condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
andHaving(array $condition): object
Create AND HAVING ... condition
Create AND HAVING ... condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
orHaving(array $condition = []): object
Create OR HAVING ... condition
Create OR HAVING ... condition
Parameters
$condition |
The array of conditions
|
Returns
|
#
|
public
|
limit(): object
Add LIMIT clause
|
#
|
public
|
count(string $field = null, string $alias = null): object
Add COUNT(*) or COUNT(field)
Add COUNT(*) or COUNT(field)
Parameters
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
public
|
max(string $field, string $alias = null): object
Add MAX(field)
Parameters
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
public
|
min(string $field, string $alias = null): object
Add MIN(field)
Parameters
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
public
|
sum(string $field, string $alias = null): object
Add SUM(field)
Parameters
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
public
|
avg(string $field, string $alias = null): object
Add AVG(field)
Parameters
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
protected
|
setAggregate(string $name, string $field = null, string $alias = null): object
Aggregation
Parameters
$name |
The function name COUNT, MAX, MIN, SUM, AVG, etc.
|
$field |
The field name
|
$alias |
The alias field name to retrieve
|
Returns
|
#
|
protected
|
buildSQL(): object
Build SQL
|
#
|
protected
|
appendExistClauses(array $exists, string $sql): string
Append EXISTS clauses to the SQL statement building
Append EXISTS clauses to the SQL statement building
Parameters
$exists |
Array of exists clauses
|
$sql |
The original SQL statement to be appended
|
|
#
|
public
|
execute(): bool|resource
Execute the query
|
#
|
public
|
getNumRows(): int
Get the number of rows in the query result
Get the number of rows in the query result
Returns
Returns the number of rows in the result set.
|
#
|
public
|
fetchRow(int $resultType = LC_FETCH_OBJECT): mixed
Fetch a query result row
Parameters
$resultType |
The optional constant indicating what type of array should be produced.
The possible values for this parameter are the constants
LC_FETCH_OBJECT, LC_FETCH_ASSOC, or LC_FETCH_ARRAY.
Default to LC_FETCH_OBJECT.
|
|
#
|
public
|
getResult(): array
Perform a query on the database and return the array of all results
Perform a query on the database and return the array of all results
Returns
The result array of objects.
If the result not found, return null.
|
#
|
public
|
getResultArray(): array
Perform a query on the database and return the array of all results in associate array
Perform a query on the database and return the array of all results in associate array
Returns
The result array of objects.
If the result not found, return null.
|
#
|
public
|
getList(string $keyField = 'id', string $valueField = 'name'): array
Perform a query on the database and return the key/value array of all results
Perform a query on the database and return the key/value array of all results
Parameters
$keyField |
The field name for the array key; default is id
|
$valueField |
The field name for the array value; default is name
|
|
#
|
public
|
getSingleResult(): object|null
Perform a query on the database and return the result object
Perform a query on the database and return the result object
Returns
The result object
If the result not found, return null.
|
#
|
public
|
fetch(): mixed
Perform a query on the database and fetch one field only
Perform a query on the database and fetch one field only
Returns
The result
If the result not found, return null.
|
#
|
public
|
getSQL(): string
Get the built SQL
|
#
|
public
|
getReadySQL(): string
Get the built SQL with the values replaced
Get the built SQL with the values replaced
|
#
|
public
static
|
validateName(string $name): boolean
Validate table name or field name
Validate table name or field name
Parameters
$name |
The table name or field name to be validated
|
|
#
|
public
static
|
quote(string $name): string
Quote table name and field name
Quote table name and field name
Parameters
$name |
The table name or field name or table.field
|
|
#
|
public
static
|
hasQuote(mixed $value): false|int|null
Check if the value has quoted table name and field name
Check if the value has quoted table name and field name
|
#
|
public
static
|
raw(string $expression, array $values = []): string
Create raw expression string
Create raw expression string
Parameters
$values |
The values to be replaced with specifier in $expression. See vsprintf.
|
|
#
|
public
static
|
buildCondition(array $cond = [], string $type = 'AND'): array
Build the SQL WHERE clause from the various condition arrays
Build the SQL WHERE clause from the various condition arrays
Parameters
$cond |
The condition array, for example
|
$type |
The condition type "AND" or "OR"; Default is "AND"
|
Returns
The built condition WHERE AND/OR
[0] string The built condition WHERE AND/OR clause
[1] array The values to bind in the condition
|
#
|
public
static
|
clearBindValues()
Clear bind values
|
#
|
public
static
|
getBindValues(): array
Get bind values
|
#
|