Adapter
Adapter
Relational Database Interface
The DB Adapter module provides classes for access to relational database via PDO (PHP Data Object) drivers and classes. This approach allows developers to use these classes to access a range of different database servers.
PDO has supporting drivers for:
Access to database functions is all implemented using a common class structure. This allows developers to create database queries in code without consideration for the underlying SQL. SQL is generated "under the hood" using a database specific driver that will automatically take care of any differences in the database servers SQL implementation.
Example Usage
$db = Hazaar\DBI\Adapter::getInstance();
$result = $this->execute('SELECT * FROM users');
while($row = $result->fetch()){
//Do things with $row here
}Properties
defaultConfig
public array $defaultConfig = array (
'encrypt' =>
array (
'cipher' => 'aes-256-ctr',
'checkstring' => '!!',
),
)config
public array $configinstances
private array $instancesloadedConfigs
private array $loadedConfigspublic $schemaManager
private Manager $schemaManagermanagerInstances
private array $managerInstancesenv
private string $enveventLog
private array $eventLogpublic $Methods
__construct
Adapter constructor.
public __construct(null $config): voidInitializes the database adapter with the provided configuration.
If an array is provided, it is merged with the default configuration. If a string is provided, it is treated as the environment name, and the configuration is loaded based on that environment. If null is provided, the configuration is loaded based on the current application environment (defined by APPLICATION_ENV) or defaults to 'development'.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | null | the configuration array, an environment string, or null to use defaults |
__call
Magic method to pass any undefined methods to the driver.
public __call(string $method, array $args): mixedThis allows the DBI Adapter to be used as a proxy to the underlying driver.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The method name to call |
$args | array | The arguments to pass to the method |
registerLogHandler
Sets a callback function that can be used to process log messages as they are generated.
public registerLogHandler(\Closure $callback): voidThe callback function provided must accept one argument. LogEvent $event.
Example, to simply echo formatted log data:
'''php $manager->registerLogHandler(function(LogEvent $event){ echo $event->toString() . PHP_EOL; }); '''
Parameters
| Parameter | Type | Description |
|---|---|---|
$callback | \Closure | The 'callable' callback function. See: is_callable(); |
can
Checks if the driver supports a specific method.
public can(string $method): boolThis method checks if the underlying database driver has a method with the given name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | the name of the method to check for |
getDriverName
Get the name of the database driver.
public getDriverName(): stringThis method returns the class name of the current driver instance, converted to uppercase.
getSchemaManager
Get the schema manager for the current database connection.
public getSchemaManager(?\Closure $logCallback): ManagerThis method initializes the schema manager if it hasn't been created yet. It uses the current environment configuration to instantiate the appropriate schema manager.
Parameters
| Parameter | Type | Description |
|---|---|---|
$logCallback | \Closure | an optional callback function for logging schema operations |
getInstance
Return an existing or create a new instance of a DBI Adapter.
public getInstance(?string $configEnv): selfThis function should be the main entrypoint to the DBI Adapter class as it implements instance tracking to reduce the number of individual connections to a database. Normally, instantiating a new DBI Adapter will create a new connection to the database, even if one already exists. This may be desired so this functionality still exists.
However, if using Hazaar\DBI\Adapter::getInstance() you will be returned an existing instance if one exists allowing a single connection to be used from multiple sections of code, without the need to pass around an existing reference.
NOTE: Only the first instance created is tracked, so it is still possible to create multiple connections by instantiating the DBI Adapter directly. The choice is yours.
Parameters
| Parameter | Type | Description |
|---|---|---|
$configEnv | string |
getSchemaManagerInstance
Get the schema manager instance for the given environment.
public getSchemaManagerInstance(?string $configEnv, ?callable $logCallback): ManagerThis method retrieves an existing instance of the schema manager if one exists for the specified environment. If not, it attempts to load the configuration for that environment and create a new Manager instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
$configEnv | string | The environment configuration to load (e.g., 'development', 'production'). If null, the default environment is used. |
$logCallback | callable | an optional callback function for logging purposes |
errorException
Generates an exception based on the last database error.
public errorException(?string $msg): voidThis method retrieves error information from the database driver. If an error occurred, it constructs an exception message including the SQL state and the driver-specific error message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$msg | string | an optional custom message to prepend to the error details |
insert
Insert a new record into the specified table.
public insert(string $tableName, mixed $data, mixed $returning): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to insert the record into |
$data | mixed | The data to be inserted. This can be an associative array or an object. |
$returning | mixed | Optional. Whether to return the inserted record. Defaults to false. |
update
Update a record in the specified table.
public update(string $tableName, mixed $data, mixed $where, mixed $returning): intParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to update the record in |
$data | mixed | The data to be updated. This can be an associative array or an object. |
$where | mixed | The WHERE clause to apply to the update. This can be an associative array or an object. |
$returning | mixed | Optional. Whether to return the updated record. Defaults to false. |
delete
Delete a record from the specified table.
public delete(string $tableName, mixed $where): intParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to delete the record from |
$where | mixed | The WHERE clause to apply to the delete. This can be an associative array or an object. |
table
Returns a Table object for the specified table name.
public table(string $tableName, ?string $alias): TableParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table |
$alias | string |
lastInsertId
Get the ID of the last inserted record.
public lastInsertId(): stringThis method checks if the underlying driver supports SQL operations. If it does, it delegates the call to the driver's lastInsertId method to retrieve the ID generated for the most recent INSERT operation.
getAttribute
Retrieve a database connection attribute.
public getAttribute(int $attribute): mixedThis method delegates the retrieval of the attribute to the underlying driver. It ensures that the driver supports SQL operations before attempting to fetch the attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the ID of the attribute to retrieve (usually a PDO::ATTR_* constant) |
setAttribute
Sets an attribute on the database driver.
public setAttribute(int $attribute, mixed $value): boolThis method allows setting specific attributes on the underlying database driver. It requires that the driver implements the SQLAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$attribute | int | the attribute identifier to set |
$value | mixed | the value to assign to the attribute |
loadConfig
Returns a Query object for the specified table name.
public loadConfig(?string $configName): ConfigParameters
| Parameter | Type | Description |
|---|---|---|
$configName | string |
listConstraints
List constraints on a table.
public listConstraints(NULL $table, NULL $type, boolean $invertType, false $): voidThis method checks if the underlying driver supports the ConstraintAPI interface. If supported, it delegates the call to the driver's listConstraints method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | NULL | The name of the table to list constraints for. If null, constraints for all tables may be returned depending on driver implementation. |
$type | NULL | The type of constraint to filter by (e.g., 'PRIMARY KEY', 'FOREIGN KEY'). If null, all types are returned. |
$invertType | boolean | if true, returns constraints that are NOT of the specified type |
$ | false |
addConstraint
Adds a constraint to the database driver.
public addConstraint(string $constraintName, array $info): boolThis method delegates the creation of a database constraint to the underlying driver. The driver must implement the ConstraintAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$constraintName | string | the name of the constraint to add |
$info | array |
dropConstraint
Drops a constraint from a table.
public dropConstraint(string $constraintName, string $tableName, bool $ifExists, bool $cascade): boolThis method delegates the operation to the underlying database driver. It ensures that the driver implements the ConstraintAPI interface before proceeding.
Parameters
| Parameter | Type | Description |
|---|---|---|
$constraintName | string | the name of the constraint to drop |
$tableName | string | the name of the table from which to drop the constraint |
$ifExists | bool | Optional. If true, prevents an error from occurring if the constraint does not exist. Defaults to false. |
$cascade | bool | Optional. If true, automatically drops objects that depend on the constraint. Defaults to false. |
listExtensions
List available extensions.
public listExtensions(): voidThis method checks if the current driver supports extensions (implements ExtensionAPI). If supported, it retrieves the list of extensions from the driver.
extensionExists
Checks if a database extension exists.
public extensionExists(string $name): boolThis method delegates the check to the underlying driver. The driver must implement the ExtensionAPI interface to support this functionality.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the extension to check for |
createExtension
Creates a database extension.
public createExtension(string $name): boolThis method delegates the creation of a database extension to the underlying driver. The driver must implement the ExtensionAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the extension to create |
dropExtension
Drops a database extension.
public dropExtension(string $name, bool $ifExists): boolThis method attempts to drop a specified extension from the database. It first checks if the underlying driver supports the ExtensionAPI interface. If the driver does not support extensions, a BadMethodCallException is thrown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the extension to drop |
$ifExists | bool | Optional. If true, prevents an error from occurring if the extension does not exist. Defaults to false. |
listGroups
List all groups in the database.
public listGroups(): voidThis method checks if the underlying driver supports the GroupAPI interface. If supported, it retrieves the list of groups from the driver.
createGroup
Creates a new group.
public createGroup(string $groupName): boolThis method delegates the group creation to the underlying driver. It requires the driver to implement the GroupAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$groupName | string | the name of the group to create |
dropGroup
Drops a group from the database.
public dropGroup(string $groupName): boolThis method delegates the group deletion to the underlying driver. The driver must implement the GroupAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$groupName | string | the name of the group to drop |
addToGroup
Adds a role to a group.
public addToGroup(string $roleName, string $parentRoleName): boolThis method delegates the operation to the underlying driver, provided the driver supports the GroupAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string | the name of the role to add |
$parentRoleName | string | the name of the parent role (group) to add the role to |
removeFromGroup
Removes a role from a group.
public removeFromGroup(string $roleName, string $parentRoleName): boolThis method delegates the removal of a role from a group to the underlying driver. The driver must implement the GroupAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string | the name of the role to remove |
$parentRoleName | string | the name of the parent group/role to remove the role from |
listIndexes
List the indexes for a table.
public listIndexes(?string $tableName): voidThis method retrieves a list of indexes for the specified table. It requires the underlying database driver to implement the IndexAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table to list indexes for. If null, the behavior depends on the driver implementation. |
indexExists
Checks if an index exists in the database.
public indexExists(string $indexName, ?string $tableName): boolThis method delegates the check to the underlying database driver. The driver must implement the IndexAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$indexName | string | the name of the index to check |
$tableName | string | the name of the table the index belongs to (optional) |
createIndex
Creates a new index on a database table.
public createIndex(string $indexName, string $tableName, mixed $idxInfo): boolThis method delegates the index creation to the underlying database driver. The driver must implement the IndexAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$indexName | string | the name of the index to create |
$tableName | string | the name of the table on which to create the index |
$idxInfo | mixed | Information defining the index (e.g., column names, index type). The structure of this parameter depends on the specific driver implementation. |
dropIndex
Drops an index from the database.
public dropIndex(string $indexName, bool $ifExists): boolThis method interfaces with the underlying driver to remove a specific index. It ensures that the driver supports index operations before attempting the drop.
Parameters
| Parameter | Type | Description |
|---|---|---|
$indexName | string | the name of the index to drop |
$ifExists | bool | whether to suppress errors if the index does not exist (default: false) |
getSchemaName
Get the name of the current schema.
public getSchemaName(): stringThis method retrieves the name of the schema currently in use by the database driver. It requires the underlying driver to implement the SchemaAPI interface.
schemaExists
Checks if a schema exists in the database.
public schemaExists(?string $schemaName): boolThis method delegates the check to the underlying driver. The driver must implement the SchemaAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$schemaName | string | The name of the schema to check. If null, the behavior depends on the driver implementation (often checks the current or default schema). |
createSchema
Creates a new schema in the database.
public createSchema(?string $schemaName): boolThis method delegates the schema creation to the underlying driver. The driver must implement the SchemaAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$schemaName | string | The name of the schema to create. If null, the behavior depends on the driver implementation. |
listSequences
List all sequences in the database.
public listSequences(): voidThis method checks if the underlying database driver supports sequences (implements SequenceAPI). If supported, it retrieves the list of sequences from the driver.
sequenceExists
Checks if a sequence exists in the database.
public sequenceExists(string $sequenceName): boolThis method delegates the check to the underlying driver. The driver must implement the SequenceAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sequenceName | string | the name of the sequence to check |
describeSequence
Describes a sequence in the database.
public describeSequence(string $name, false $): voidThis method retrieves information about a specific sequence from the database driver. It requires the underlying driver to implement the SequenceAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the sequence to describe |
$ | false |
createSequence
Creates a new sequence in the database.
public createSequence(string $name, array $sequenceInfo, bool $ifNotExists): boolThis method delegates the sequence creation to the underlying driver. It first checks if the driver implements the SequenceAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the sequence to create |
$sequenceInfo | array | |
$ifNotExists | bool | If true, the sequence will only be created if it does not already exist. Defaults to false. |
dropSequence
Drops a sequence from the database.
public dropSequence(string $name, bool $ifExists): boolThis method allows you to remove a sequence from the database. It first checks if the underlying database driver supports sequences (implements the SequenceAPI interface).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the sequence to drop |
$ifExists | bool | Optional. If true, the method will not throw an error if the sequence does not exist. Defaults to false. |
nextSequenceValue
Get the next value from a sequence.
public nextSequenceValue(string $name): intThis method retrieves the next available value from the specified sequence. It requires the underlying driver to implement the SequenceAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the sequence |
setSequenceValue
Sets the current value of a sequence.
public setSequenceValue(string $name, int $value): boolThis method delegates the operation to the underlying driver. The driver must implement the SequenceAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the sequence |
$value | int | the value to set the sequence to |
createDatabase
Creates a new database.
public createDatabase(string $name): boolThis method checks if the underlying driver supports SQL operations. If it does, it delegates the database creation to the driver.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the database to create |
exec
Execute a raw SQL statement.
public exec(string $sql): intThis method executes a raw SQL statement using the underlying driver.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the SQL statement to execute |
query
Executes a raw SQL query using the underlying driver.
public query(string $sql): ResultThis method acts as a proxy to the driver's query method. It ensures that the current driver supports SQL operations (implements SQLAPI) before attempting to execute the query.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the raw SQL query string to execute |
quote
Quotes a string for use in a query.
public quote(mixed $string, int $type = '\PDO::PARAM_STR'): stringThis method delegates the quoting process to the underlying driver. It ensures that the driver supports SQL operations before attempting to quote the string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | mixed | the string to be quoted |
$type | int | Provides a data type hint for drivers that have alternate quoting styles. Defaults to \PDO::PARAM_STR. |
setTimezone
Sets the timezone for the database connection.
public setTimezone(string $tz): boolThis method attempts to set the timezone for the current database session. It requires the underlying driver to be an instance of SQLAPI.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tz | string | The timezone to set (e.g., 'UTC', 'America/New_York'). |
errorInfo
Returns extended error information associated with the last operation on the database handle.
public errorInfo(false $): voidThis method delegates to the underlying driver's errorInfo method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$ | false |
errorCode
Returns the error code associated with the last operation.
public errorCode(): stringThis method delegates the retrieval of the error code to the underlying driver. It requires the driver to be an instance of SQLAPI.
getQueryBuilder
Get the query builder for the current driver.
public getQueryBuilder(): QueryBuilderInterfaceThis method checks if the underlying driver supports SQL operations (implements SQLAPI). If supported, it returns the query builder instance associated with that driver.
repair
Repairs the database tables.
public repair(): boolThis method checks if the underlying driver supports SQL operations. If it does, it attempts to repair the database tables using the driver's repair method.
lastQueryString
Get the last executed query string.
public lastQueryString(): stringThis method retrieves the SQL string of the last query executed by the driver. It requires the underlying driver to be an instance of SQLAPI.
listFunctions
List all stored functions in the database.
public listFunctions(bool $includeParameters): voidThis method retrieves a list of stored functions available in the database. It delegates the request to the underlying driver, provided the driver implements the StoredFunctionAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$includeParameters | bool | Whether to include function parameters in the result. Defaults to false. |
functionExists
Checks if a stored function exists in the database.
public functionExists(string $functionName, ?string $argTypes): boolThis method delegates the check to the underlying database driver. The driver must implement the StoredFunctionAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$functionName | string | the name of the stored function to check |
$argTypes | string | optional argument types to distinguish between overloaded functions (if supported by the driver) |
describeFunction
Describes a stored function in the database.
public describeFunction(string $name, false $): voidThis method retrieves metadata about a specific stored function. It requires the underlying database driver to implement the StoredFunctionAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the stored function to describe |
$ | false |
createFunction
Creates a stored function in the database.
public createFunction(string $name, mixed $spec, bool $replace): boolThis method delegates the creation of a stored function to the underlying database driver. The driver must implement the StoredFunctionAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the function to create |
$spec | mixed | The specification of the function. The format depends on the driver implementation. |
$replace | bool | Whether to replace the function if it already exists. Defaults to false. |
dropFunction
Drops a stored function from the database.
public dropFunction(string $name, null $argTypes, bool $cascade, bool $ifExists): boolThis method interfaces with the underlying database driver to remove a stored function. It requires the driver to implement the StoredFunctionAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the function to drop |
$argTypes | null | The argument types of the function. This is necessary for databases that support function overloading (e.g., PostgreSQL). |
$cascade | bool | if true, automatically drop objects that depend on the function (such as operators or triggers), and in turn all objects that depend on those objects |
$ifExists | bool | If true, do not throw an error if the function does not exist. A notice is issued in this case. |
listTables
List all tables in the database.
public listTables(): voidThis method delegates the task of listing tables to the underlying driver. The driver must implement the TableAPI interface.
tableExists
Checks if a table exists in the database.
public tableExists(string $tableName): boolThis method delegates the check to the underlying database driver. The driver must implement the TableAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to check |
createTable
Creates a new table in the database.
public createTable(string $tableName, mixed $columns): boolThis method delegates the table creation to the underlying driver. The driver must implement the TableAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to create |
$columns | mixed | The column definitions for the new table. The format depends on the driver implementation. |
describeTable
Get a description of a table.
public describeTable(string $tableName, ?string $sort, false $): voidThis method retrieves the schema description for a specified table. It delegates the operation to the underlying driver, provided the driver implements the TableAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to describe |
$sort | string | optional column to sort the results by |
$ | false |
renameTable
Renames a table in the database.
public renameTable(string $fromName, string $toName): boolThis method delegates the renaming operation to the underlying database driver. It requires the driver to implement the TableAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fromName | string | the current name of the table |
$toName | string | the new name for the table |
dropTable
Drops a table from the database.
public dropTable(string $name, bool $ifExists, bool $cascade): boolThis method delegates the table dropping operation to the underlying driver. It ensures that the driver implements the TableAPI interface before attempting the operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the table to drop |
$ifExists | bool | Whether to check if the table exists before attempting to drop it. If true, no error is raised if the table does not exist. |
$cascade | bool | whether to automatically drop objects that depend on the table (such as views) |
addColumn
Adds a new column to an existing table.
public addColumn(string $tableName, mixed $columnSpec): boolThis method delegates the column addition to the underlying driver. The driver must implement the TableAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to modify |
$columnSpec | mixed | The specification for the new column. The format depends on the underlying driver. |
alterColumn
Alters a column in a database table.
public alterColumn(string $tableName, string $column, mixed $columnSpec): boolThis method delegates the column alteration to the underlying driver. The driver must implement the TableAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table containing the column to alter |
$column | string | the name of the column to alter |
$columnSpec | mixed | The new specification for the column. The format depends on the driver implementation. |
dropColumn
Drops a column from a table.
public dropColumn(string $tableName, string $column, bool $ifExists): boolParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table |
$column | string | the name of the column to drop |
$ifExists | bool | whether to check if the column exists before dropping it |
truncate
Truncate a table.
public truncate(string $tableName, bool $only, bool $restartIdentity, bool $cascade): boolThis method empties a table completely. It requires the underlying driver to implement the TableAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the name of the table to truncate |
$only | bool | If TRUE, only the named table is truncated. If FALSE, the table and all its descendants are truncated. |
$restartIdentity | bool | if TRUE, automatically restart sequences owned by columns of the truncated table(s) |
$cascade | bool | if TRUE, 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 |
begin
Initiates a database transaction.
public begin(): boolThis method checks if the underlying driver supports transactions by verifying if it implements the TransactionAPI interface. If supported, it begins a new transaction.
commit
Commits a transaction.
public commit(): boolThis method commits the current transaction on the database driver.
cancel
Cancels the currently active database transaction.
public cancel(): boolThis method rolls back the current transaction if one is active.
inTransaction
Checks if the driver is currently in a transaction.
public inTransaction(): boolThis method verifies if the underlying database driver supports transactions (implements the TransactionAPI interface) and then checks the transaction status.
listTriggers
List triggers for a table.
public listTriggers(?string $tableName): voidThis method retrieves a list of triggers associated with the specified table. It delegates the request to the underlying driver, provided the driver supports the TriggerAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table to list triggers for. If null, triggers for all tables may be returned depending on driver implementation. |
triggerExists
Checks if a trigger exists in the database.
public triggerExists(string $triggerName, string $tableName): boolThis method delegates the check to the underlying driver. The driver must implement the TriggerAPI interface to support this functionality.
Parameters
| Parameter | Type | Description |
|---|---|---|
$triggerName | string | the name of the trigger to check for |
$tableName | string | the name of the table associated with the trigger |
describeTrigger
Describes a trigger in the database.
public describeTrigger(string $triggerName, false $): voidThis method retrieves the details of a specific trigger from the database driver. It requires the underlying driver to implement the TriggerAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$triggerName | string | the name of the trigger to describe |
$ | false |
createTrigger
Creates a new database trigger.
public createTrigger(string $triggerName, string $tableName, mixed $spec): boolThis method delegates the trigger creation to the underlying database driver. It first checks if the driver implements the TriggerAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$triggerName | string | the name of the trigger to create |
$tableName | string | the name of the table the trigger is associated with |
$spec | mixed | The trigger specification. This can be an array or object defining the trigger's timing, event, and action. Defaults to an empty array. |
dropTrigger
Drops a trigger from the database.
public dropTrigger(string $triggerName, string $tableName, bool $ifExists, bool $cascade): boolThis method allows you to remove an existing trigger from a specific table. It delegates the operation to the underlying database driver, provided the driver implements the TriggerAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$triggerName | string | the name of the trigger to drop |
$tableName | string | the name of the table the trigger is associated with |
$ifExists | bool | Optional. If true, adds a clause to prevent errors if the trigger does not exist. Default is false. |
$cascade | bool | Optional. If true, automatically drops objects that depend on the trigger. Default is false. |
listUsers
List all users in the database.
public listUsers(): voidThis method delegates the request to the underlying driver. The driver must implement the UserAPI interface to support this functionality.
createUser
Creates a new database user.
public createUser(string $name, ?string $password, array $privileges): boolThis method delegates the user creation process to the underlying driver. It requires the driver to implement the UserAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the username for the new user |
$password | string | The password for the new user. Defaults to null. |
$privileges | array | An array of privileges to grant to the user. Defaults to an empty array. |
dropUser
Drops a user from the database.
public dropUser(string $name, bool $ifExists): boolThis method delegates the user deletion to the underlying driver. It first checks if the driver implements the UserAPI interface. If the driver does not support user management, a BadMethodCallException is thrown.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the user to drop |
$ifExists | bool | Optional. If true, no error is reported if the user does not exist. Defaults to false. |
grant
Grant a role to a user on a specific object.
public grant(string $role, string $to, string $on): boolThis method delegates the grant operation to the underlying driver. The driver must implement the UserAPI interface to support this functionality.
Parameters
| Parameter | Type | Description |
|---|---|---|
$role | string | The role(s) to grant. Can be a single role string or an array of roles. |
$to | string | the user or entity to whom the role is being granted |
$on | string | the object or resource on which the role is being granted |
revoke
Revokes a role or privilege from a user or role on a specific object.
public revoke(string $role, string $from, string $on): boolThis method delegates the revocation process to the underlying driver, provided the driver implements the UserAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$role | string | The role(s) or privilege(s) to revoke. Can be a single string or an array of strings. |
$from | string | the user or role from whom the privilege is being revoked |
$on | string | The object (e.g., table, database) on which the privilege is being revoked. |
listViews
List all views in the database.
public listViews(): voidThis method checks if the underlying driver supports views (implements ViewAPI). If supported, it returns a list of views from the driver.
viewExists
Checks if a view exists in the database.
public viewExists(string $viewName): boolThis method delegates the check to the underlying driver. The driver must implement the ViewAPI interface to support this operation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$viewName | string | the name of the view to check for existence |
describeView
Describes a database view.
public describeView(string $name, false $): voidThis method retrieves the structure and metadata of a specific database view. It requires the underlying database driver to implement the ViewAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the view to describe |
$ | false |
createView
Creates a new database view.
public createView(string $name, mixed $content, bool $replace): boolThis method delegates the creation of the view to the underlying driver. The driver must implement the ViewAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the view to create |
$content | mixed | the content of the view (usually a SELECT statement or query object) |
$replace | bool | Whether to replace the view if it already exists. Defaults to false. |
dropView
Drops a view from the database.
public dropView(string $name, bool $ifExists, bool $cascade): boolParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the view to drop |
$ifExists | bool | whether to check if the view exists before attempting to drop it |
$cascade | bool | whether to cascade the drop to dependent objects |
prepareQuery
Prepares a SQL query for execution using the underlying database driver.
public prepareQuery(QueryBuilderInterface $queryBuilder): StatementThis method delegates the preparation of the query to the driver, provided the driver implements the StatementAPI interface.
Parameters
| Parameter | Type | Description |
|---|---|---|
$queryBuilder | QueryBuilderInterface | the query builder object containing the SQL to prepare |
prepare
Prepares a SQL statement for execution.
public prepare(string $sql): StatementThis method delegates the preparation of the SQL statement to the underlying driver. The driver must implement the StatementAPI interface to support prepared statements.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | the SQL statement to prepare |
log
Log a message to the database adapter event log.
public log(string $msg): voidThis method creates a new LogEntry and appends it to the internal event log. If an event log callback has been registered, it will immediately process and flush the pending log entries by passing them to the callback function.
Parameters
| Parameter | Type | Description |
|---|---|---|
$msg | string | the message to log |
getEventLog
Retrieves the log of database events.
public getEventLog(): voidThis method returns an array containing the history of events or queries executed by the database adapter.
getDriverClass
private getDriverClass(string $driver): stringParameters
| Parameter | Type | Description |
|---|---|---|
$driver | string |
reconfigure
private reconfigure(bool $reconnect): boolParameters
| Parameter | Type | Description |
|---|---|---|
$reconnect | bool |
Generated by Hazaar API Doc Generator on Wed, 07 Jan 2026 11:29:59 +0000