Table
Table
Fluent table query facade for building and executing adapter-backed SQL operations.
class TableThis class wraps a query builder and provides convenience methods for selecting, inserting, updating, deleting, and metadata operations scoped to a single database table.
Properties
adapter
Database adapter used to prepare and execute SQL statements.
private Adapter $adapterqueryBuilder
Query builder instance used to compose SQL for this table context.
private QueryBuilder $queryBuildername
Physical table name in the connected database.
private string $namealias
public string $aliasMethods
__construct
Create a table query context bound to a specific adapter and table.
public __construct(Adapter $adapter, string $name, ?string $alias): voidParameters
| Parameter | Type | Description |
|---|---|---|
$adapter | Adapter | active database adapter |
$name | string | database table name |
$alias | string | optional table alias for generated SQL |
__toString
Cast the current query builder state to SQL.
public __toString(): stringtoString
Get the SQL string for the current query state.
public toString(): stringgetName
Get the configured table name.
public getName(): stringexists
Determine whether the table or matching records exist.
public exists(mixed $criteria): boolWhen $criteria is null, this checks table existence in the schema. Otherwise it executes an EXISTS query against this table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteria | mixed | optional query criteria for row existence checks |
select
Define the columns to select.
public select(mixed $columns = '*'): selfParameters
| Parameter | Type | Description |
|---|---|---|
$columns | mixed | *, column name, or builder-supported column map/list |
distinct
Mark the SELECT as DISTINCT for one or more columns.
public distinct(string $columns): selfParameters
| Parameter | Type | Description |
|---|---|---|
$columns | string |
from
Override the FROM clause for the current query.
public from(string $table, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | source table name |
$alias | string | optional source alias |
limit
Set a LIMIT clause for the query.
public limit(int $limit): selfParameters
| Parameter | Type | Description |
|---|---|---|
$limit | int | maximum number of rows to return |
offset
Set an OFFSET clause for the query.
public offset(int $offset): selfParameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | number of rows to skip before returning data |
order
Add ORDER BY columns to the current query.
public order(string $columns, int $direction = 'SORT_ASC'): selfParameters
| Parameter | Type | Description |
|---|---|---|
$columns | string | |
$direction | int | sort direction (SORT_ASC or SORT_DESC) for string input |
group
Add GROUP BY columns to the query.
public group(string $columns): selfParameters
| Parameter | Type | Description |
|---|---|---|
$columns | string |
having
Add a HAVING clause to the grouped query.
public having(array $having): selfParameters
| Parameter | Type | Description |
|---|---|---|
$having | array |
join
Join another table to the current query.
public join(string $table, string $on, ?string $alias, string $type = 'INNER'): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
$type | string | join type (INNER, LEFT, RIGHT, OUTER, FULL, CROSS) |
leftJoin
Add a LEFT JOIN to the current query.
public leftJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
rightJoin
Add a RIGHT JOIN to the current query.
public rightJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
innerJoin
Add an INNER JOIN to the current query.
public innerJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
outerJoin
Add an OUTER JOIN to the current query.
public outerJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
fullJoin
Add a FULL JOIN to the current query.
public fullJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
crossJoin
Add a CROSS JOIN to the current query.
public crossJoin(string $table, string $on, ?string $alias): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | string | target table to join |
$on | string | join condition criteria |
$alias | string | optional alias for the joined table |
union
Combine this SELECT with another query using UNION.
public union(Table $table): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | Table | table containing the query to union with |
unionAll
Combine this SELECT with another query using UNION ALL.
public unionAll(Table $table): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | Table | table containing the query to union with |
intersect
Intersect this SELECT with another query using INTERSECT.
public intersect(Table $table): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | Table | table containing the query to intersect with |
except
Exclude rows from this SELECT that appear in another query using EXCEPT.
public except(Table $table): selfParameters
| Parameter | Type | Description |
|---|---|---|
$table | Table | table containing the query to exclude |
prepareSelect
Prepare a reusable SELECT statement with named criteria placeholders.
public prepareSelect(array $columns, array $criteriaNames): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$columns | array | columns to include in the projection |
$criteriaNames | array | columns exposed as WHERE placeholders |
insert
Insert one or more rows into the table.
public insert(mixed $values, null $returning, null $conflictTarget, null $conflictUpdate, ?Table $table): mixedSupports optional RETURNING and conflict handling (upsert-like behavior) based on adapter capabilities.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed | row data or row set to insert |
$returning | null | |
$conflictTarget | null | |
$conflictUpdate | null | |
$table | Table | reserved parameter for API compatibility |
prepareInsert
Prepare a reusable INSERT statement from a list of columns.
public prepareInsert(array $columnNames): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$columnNames | array | column names that will be accepted as values |
insertModel
Insert a model instance and hydrate it with returned fields when available.
public insertModel(Struct $model, null $conflictTarget, mixed $conflictUpdate): StructParameters
| Parameter | Type | Description |
|---|---|---|
$model | Struct | model to insert |
$conflictTarget | null | |
$conflictUpdate | mixed | conflict update specification |
update
Update rows matching the provided criteria.
public update(mixed $values, string $where, mixed $returning): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed | column values to write |
$where | string | filter criteria for selecting rows to update |
$returning | mixed | optional columns/expressions to return after update |
prepareUpdate
Prepare a reusable UPDATE statement with named update and criteria fields.
public prepareUpdate(array $columnNames, array $criteriaNames): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$columnNames | array | columns that will be updated |
$criteriaNames | array | columns used in the WHERE clause |
updateModel
Update persisted data for a model using selected key fields as criteria.
public updateModel(Struct $model, string $where): StructParameters
| Parameter | Type | Description |
|---|---|---|
$model | Struct | model instance to update |
$where | string | model key(s) used to build update criteria |
delete
Delete rows matching the provided criteria.
public delete(string $where): intParameters
| Parameter | Type | Description |
|---|---|---|
$where | string |
prepareDelete
Prepare a reusable DELETE statement with named criteria placeholders.
public prepareDelete(array $criteriaNames): StatementParameters
| Parameter | Type | Description |
|---|---|---|
$criteriaNames | array | columns used as WHERE placeholders |
deleteAll
Delete all rows from the table.
public deleteAll(): inttruncate
Truncate all rows from the table.
public truncate(bool $cascade): boolParameters
| Parameter | Type | Description |
|---|---|---|
$cascade | bool | whether related dependent data should also be removed |
find
Execute a SELECT query with optional criteria and selected columns.
public find(mixed $where, mixed $columns): ResultParameters
| Parameter | Type | Description |
|---|---|---|
$where | mixed | optional criteria applied to the query |
$columns | mixed |
where
Add a WHERE clause to the current query.
public where(string $where): selfParameters
| Parameter | Type | Description |
|---|---|---|
$where | string |
findOne
Fetch the first matching row as an associative array.
public findOne(string $where, mixed $columns, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$where | string | |
$columns | mixed | |
$ | false |
findOneModel
Fetch the first matching row and hydrate it into a model instance.
public findOneModel(string $model, string $where): StructParameters
| Parameter | Type | Description |
|---|---|---|
$model | string | fully qualified model class name |
$where | string | row selection criteria |
findOneRow
Fetch the first matching row as a Row object.
public findOneRow(string $where, null $columns): RowParameters
| Parameter | Type | Description |
|---|---|---|
$where | string | |
$columns | null |
fetchAll
Fetch all rows for the current query.
public fetchAll(?string $keyColumn, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$keyColumn | string | optional column used as the key in the returned array |
$ | false |
fetchAllColumn
Fetch every value from a single selected column.
public fetchAllColumn(string $columnName, mixed $fetchArgument, bool $clobberDupNamedCols, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$columnName | string | column to extract |
$fetchArgument | mixed | reserved parameter for API compatibility |
$clobberDupNamedCols | bool | reserved parameter for API compatibility |
$ | false |
toArray
Materialize the current query result as an array of row arrays.
public toArray(): voidcount
Count rows matching the current query criteria.
public count(): intdescribe
Describe table columns using adapter-specific metadata.
public describe(false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$ | false |
errorInfo
Get the adapter's most recent error information.
public errorInfo(): voidexecute
Execute the current SQL and return the first column from the first row.
public execute(): intcreate
Create the table in the database using the provided column definition.
public create(mixed $columns): boolParameters
| Parameter | Type | Description |
|---|---|---|
$columns | mixed | adapter-specific table column/schema definition |
drop
Drop the table from the database.
public drop(): boolgetPrimaryKey
Get the primary key constraint metadata for this table.
public getPrimaryKey(false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$ | false |
reset
Reset the query builder state for this table context.
public reset(): selfGenerated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000