QueryBuilder
QueryBuilder
Interface for building SQL queries in a database-agnostic way.
interface QueryBuilderProvides methods for constructing, manipulating, and rendering SQL statements for CRUD operations, joins, grouping, ordering, and schema management. Implementations must support chaining and flexible query composition.
Methods
setReservedWords
public setReservedWords(array $words): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$words | array |
setSupportsIlike
Sets whether the target driver supports a native case-insensitive LIKE (ILIKE).
public setSupportsIlike(bool $supported): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$supported | bool |
create
Generates a CREATE statement for a table or object.
public create(string $name, string $type, bool $ifNotExists): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$type | string | |
$ifNotExists | bool |
insert
Generates an INSERT statement for the specified fields.
public insert(mixed $fields): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$fields | mixed |
update
public update(array $fields): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$fields | array |
delete
Generates a DELETE statement for the current query context.
public delete(): selfReturns: self
truncate
Generates a TRUNCATE statement for the current table.
public truncate(bool $cascade): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$cascade | bool |
count
Generates a COUNT statement for the current query context.
public count(): stringReturns: string
exists
Generates an EXISTS statement for the specified table and criteria.
public exists(string $table, null|array|string $criteria): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$criteria | null | array |
select
Specifies columns to select in the query.
public select(mixed $columns): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | mixed |
distinct
Specifies DISTINCT columns for the query.
public distinct(string $columns): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | string |
table
Sets the table for the query, optionally with an alias.
public table(string $table, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$alias | string |
from
Sets the FROM clause for the query, optionally with an alias.
public from(string $table, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | |
$alias | string |
where
public where(array|string $criteria): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteria | array | string |
group
Adds GROUP BY clause to the query.
public group(string $column): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$column | string |
having
public having(array $criteria): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteria | array |
window
public window(string $name, string $partitionBy, array|string|null $orderBy): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$partitionBy | string | |
$orderBy | array | string |
join
Join a table to the current query using the provided join criteria.
public join(string $references, array|string|null $on, ?string $alias, string $type = 'INNER'): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$references | string | |
$on | array | string |
$alias | string | |
$type | string |
union
Adds a UNION clause with another query.
public union(QueryBuilder $query): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | Hazaar\DBI\Interface\QueryBuilder |
unionAll
Adds a UNION ALL clause with another query.
public unionAll(QueryBuilder $query): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | Hazaar\DBI\Interface\QueryBuilder |
intersect
Adds an INTERSECT clause with another query.
public intersect(QueryBuilder $query): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | Hazaar\DBI\Interface\QueryBuilder |
except
Adds an EXCEPT clause with another query.
public except(QueryBuilder $query): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | Hazaar\DBI\Interface\QueryBuilder |
order
public order(array|string $columns, int $sortDirection = 'SORT_ASC'): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | array | string |
$sortDirection | int |
limit
Sets the LIMIT clause for the query.
public limit(int $limit): int|selfReturns: int|self
Parameters
| Parameter | Type | Description |
|---|---|---|
$limit | int |
offset
Sets the OFFSET clause for the query.
public offset(int $offset): int|selfReturns: int|self
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int |
toString
Returns the SQL string representation of the query.
public toString(): stringReturns: string
getSchemaName
Returns the schema name for the current query context.
public getSchemaName(): ?stringReturns: string
parseSchemaName
public parseSchemaName(string $tableName): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string |
schemaName
Returns the fully qualified schema name for a table.
public schemaName(string $tableName): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string |
quoteSpecial
Quotes a value for use in SQL, handling special cases.
public quoteSpecial(mixed $value): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed |
field
Quotes or formats a field name for SQL usage.
public field(string $string): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string |
prepareFields
public prepareFields(mixed $fields, array $exclude, array $tables): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$fields | mixed | |
$exclude | array | |
$tables | array |
getSelectGroups
Returns the select-group map built up by the last prepareFields() call, mapping each
public getSelectGroups(): arrayReturns: array
resolved table alias/name (or generated lookup key) to the result key its columns should be nested under. Needed by Result to reconstruct grouped/nested rows from a flat PDO result.
prepareValue
Prepares a value for SQL binding, handling type and quoting.
public prepareValue(string $key, mixed $value): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed |
prepareArrayAliases
public prepareArrayAliases(array $array): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$array | array |
prepareCriteria
public prepareCriteria(array|string $criteria, string $bindType = 'AND', string $tissue = '=', ?string $parentRef, bool $setKey = true): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteria | array | string |
$bindType | string | |
$tissue | string | |
$parentRef | string | |
$setKey | bool |
reset
Resets the internal state of the query builder, clearing all clauses and parameters.
public reset(): selfReturns: self
getCriteriaValues
public getCriteriaValues(): arrayReturns: array
prepareCriteriaValues
public prepareCriteriaValues(array $paramValues): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$paramValues | array |
returning
Specifies columns to return from an INSERT, UPDATE, or DELETE statement (RETURNING clause).
public returning(mixed $columns): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | mixed |
onConflict
public onConflict(array|string|null $target, array|bool|null $update): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$target | array | string |
$update | array | bool |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000