Table
Table
Relational Database Interface - Table Class
The Table class is used to access table data via an abstracted interface. That means that now SQL is used to access table data and queries are generated automatically using access methods. The generation of SQL is then handled by the database driver so that database specific SQL can be used when required. This allows a common interface for accessing data that is compatible across all of the database drivers.
h2. Example Usage
$db = new Hazaar\DBI();
$result = $db->users->find(array('uname' => 'myusername'))->join('images', array('image' => array('$ref' => 'images.id')));
while($row = $result->fetch()){
//Do things with $row here
}
Properties
adapter
protected Adapter $adapter
tableName
public string $tableName
alias
public string $alias
tables
protected array $tables
criteria
protected array $criteria
fields
protected array $fields
group
protected array $group
having
protected array $having
window
protected array $window
joins
protected array $joins
combine
protected array $combine
order
protected array $order
fetch
protected array $fetch
distinct
public bool $distinct
limit
public int $limit
offset
public int $offset
result
public Result $result
Methods
__construct
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$adapter | Adapter | |
$tableName | string | |
$alias | string |
__toString
public __toString({Array})
find
Search for records on a table with the provided search criteria.
public find({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria to find records for |
$fields | mixed | a field definition |
findOne
Find a single row using the provided criteria, fields and order and return is as an array.
public findOne({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria |
$fields | mixed | a field definition array |
$order | string | A valid order definition |
findOneRow
Find a single row using the provided criteria, fields and order and return is as an array.
public findOneRow({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria |
$fields | mixed | a field definition array |
$order | NULL | A valid order definition |
exists
Check if rows exist in the database.
public exists({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the search criteria to check for existing rows |
toString
Return the current selection as a valid SQL string.
public toString({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$terminate_with_colon | bool | |
$untable | bool |
execute
Execute the current selection.
public execute({Array})
prepare
Prepare a statement for execution and returns a new \Hazaar\Result object.
public prepare({Array})
The criteria can contain zero or more names (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. Both named and question mark parameter markers cannot be used within the same statement template; only one or the other parameter style. Use these parameters to bind any user-input, do not include the user-input directly in the query.
You must include a unique parameter marker for each value you wish to pass in to the statement when you call \Hazaar\Result::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement.
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | the query selection criteria |
$fields | mixed | the field selection |
$name | string |
fields
Defined the current field selection definition.
public fields({Array})
select
Alias for Hazaar\DBI\Table::fields().
public select({Array})
distinct
Selects only distinct rows that match based on the specified expressions.
public distinct({Array})
where
Defines a WHERE selection criteria.
public where({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed |
group
public group({Array})
having
public having({Array})
window
public window({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$name | string | |
$partitionBy | string | |
$orderBy | string |
join
Join a table to the current query using the provided join criteria.
public join({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$references | string | the table to join to the query |
$on | string | The join criteria. This is mostly just a standard query selection criteria. |
$alias | string | an alias to use for the joined table |
$type | string | the join type such as INNER, OUTER, LEFT, RIGHT, etc |
innerJoin
public innerJoin({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | string | |
$alias | string |
leftJoin
public leftJoin({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | string | |
$alias | string |
rightJoin
public rightJoin({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | string | |
$alias | string |
fullJoin
public fullJoin({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$references | string | |
$on | string | |
$alias | string |
sort
public sort({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$fieldDef | string | |
$sortFlags | int |
limit
public limit({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$limit | int |
offset
public offset({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | int |
insert
Insert a record into a database table.
public insert({Array})
Using $updateColumns it's possible to perform an "upsert". An upsert is an INSERT, that when it fails, columns can be updated in the existing row.
Parameters
Parameter | Type | Description |
---|---|---|
$fields | mixed | the fields to be inserted |
$returning | mixed | a column to return when the row is inserted (usually the primary key) |
$updateColumns | string | the names of the columns to be updated if the row exists |
$updateWhere | array | Not used yet |
$ | int |
update
public update({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed | |
$fields | mixed | |
$returning | mixed | |
$ | int |
delete
public delete({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$criteria | mixed |
deleteAll
public deleteAll({Array})
row
public row({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | int |
rows
public rows({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$ | false |
fetch
public fetch({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$cursorOrientation | int | |
$offset | int | |
$clobberDupNamedCols | bool | |
$ | false |
fetchColumn
public fetchColumn({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$column | int | |
$ | false |
fetchAll
public fetchAll({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$fetchArgument | mixed | |
$clobberDupNamedCols | bool |
fetchAllColumn
public fetchAllColumn({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$columnName | string | |
$fetchArgument | mixed | |
$clobberDupNamedCols | bool |
reset
public reset({Array})
current
public current({Array})
key
public key({Array})
next
public next({Array})
rewind
public rewind({Array})
valid
public valid({Array})
count
public count({Array})
getResult
public getResult({Array})
collate
Collates a result into a simple key/value array.
public collate({Array})
This is useful for generating SELECT lists directly from a resultset.
Parameters
Parameter | Type | Description |
---|---|---|
$indexColumn | string | the column to use as the array index |
$valueColumn | string | the column to use as the array value |
$groupColumn | string | optional column name to group items by |
truncate
Truncate the table.
public truncate({Array})
Truncating a table quickly removes all rows from a set of tables. It has the same effect as Hazaar\DBI\Table::deleteAll() on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.
Parameters
Parameter | Type | Description |
---|---|---|
$only | bool | Only the named table is truncated. If FALSE, the table and all its descendant tables (if any) are truncated. |
$restartIdentity | bool | Automatically restart sequences owned by columns of the truncated table(s). The default is to no restart. |
$cascade | bool | If TRUE, automatically truncate all tables that have foreign-key references to any of the named tables, or |
to any tables added to the group due to CASCADE. If FALSE, Refuse to truncate if any of the tables have
foreign-key references from tables that are not listed in the command. FALSE is the default. |
listUsedTables
List all tables that will be accessed in this table query.
public listUsedTables({Array})
Returns an array of table names of all tables used in this query, including joins.
from
Add a table or function to the FROM table reference.
public from({Array})
PostgreSQL combines table references using a cross-join.
See: here for examples.
Parameters
Parameter | Type | Description |
---|---|---|
$table | string | |
$alias | string |
union
Append a table query using a UNION.
public union({Array})
This will return results from both queries combined together.
Parameters
Parameter | Type | Description |
---|---|---|
$query | Table |
intersect
Append a table query using an INTERSECT.
public intersect({Array})
This will return only results that exist in both queries.
Parameters
Parameter | Type | Description |
---|---|---|
$query | Table |
except
Append a table query using an EXCEPT.
public except({Array})
This will return results from the first query except if they appear in the second.
Parameters
Parameter | Type | Description |
---|---|---|
$query | Table |
errorInfo
public errorInfo({Array})
prepareFrom
private prepareFrom({Array})
tables
private tables({Array})
prepareOrder
private prepareOrder({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$orderDefinition | string |
Generated by Hazaar API Doc Generator