Adapter
Adapter
- Full name:
\Hazaar\DBI\Adapter
Properties
defaultConfig
public static array<string,int|string> $defaultConfig
- This property is static.
config
public \Hazaar\Map $config
driver
public \Hazaar\DBI\DBD\BaseDriver $driver
loadedConfigs
private static \Hazaar\Application\Config[] $loadedConfigs
- This property is static.
schemaManager
private ?\Hazaar\DBI\Schema\Manager $schemaManager
connections
private static \Hazaar\DBI\DBD\BaseDriver[] $connections
- This property is static.
instances
private static \Hazaar\DBI\Adapter[] $instances
- This property is static.
managerInstances
private static \Hazaar\DBI\Schema\Manager[] $managerInstances
- This property is static.
statements
private \PDOStatement[] $statements
dsn
private ?string $dsn
Methods
__construct
Hazaar DBI Constructor.
public __construct(array|\Hazaar\Map|string $config = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$config | array|\Hazaar\Map|string | An array of configuration options to instantiate the DBI Adapter. This can also be a Hazaar MVC configuration environment if DBI is being used by an HMVC application. |
__call
public __call(string $method, array $args): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$method | string | |
$args | array |
getInstance
Return an existing or create a new instance of a DBI Adapter.
public static getInstance(?string $configEnv = null): \Hazaar\DBI\Adapter
This 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.
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$configEnv | ?string |
getSchemaManagerInstance
Return an existing or create a new instance of a DBI Schema Manager;.
public static getSchemaManagerInstance(?string $configEnv = null, ?callable $logCallback = null): \Hazaar\DBI\Schema\Manager
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$configEnv | ?string | |
$logCallback | ?callable |
getDriverClass
public static getDriverClass(string $driver): string
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$driver | string |
setDefaultConfig
public static setDefaultConfig(string $config, ?string $env = null): bool
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$config | string | |
$env | ?string |
getDefaultConfig
public static getDefaultConfig(?string& $configName = null): false|\Hazaar\Map
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$configName | ?string |
connect
public connect(?string $dsn = null, ?string $username = null, ?string $password = null, array<int,bool> $driverOptions = null, bool $reconnect = false): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$dsn | ?string | |
$username | ?string | |
$password | ?string | |
$driverOptions | array<int,bool> | |
$reconnect | bool |
getDriver
public getDriver(): string
getAvailableDrivers
public getAvailableDrivers(): string[]
subquery
Build a sub-query using an existing query.
public subquery(string|\Hazaar\DBI\Table $subquery, string $name): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$subquery | string|\Hazaar\DBI\Table | Table The existing query to use as the sub-query |
$name | string | The named alias of the sub-query |
query
public query(string $sql): false|\Hazaar\DBI\Result
Parameters:
Parameter | Type | Description |
---|---|---|
$sql | string |
exists
public exists(string $table, mixed $criteria = []): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$table | string | |
$criteria | mixed |
table
public table(string $name, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$alias | ?string |
from
public from(string $name, ?string $alias = null): \Hazaar\DBI\Table
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$alias | ?string |
call
public call(string $method, string[] $args = [], mixed $criteria = null): \Hazaar\DBI\Result
Parameters:
Parameter | Type | Description |
---|---|---|
$method | string | |
$args | string[] | |
$criteria | mixed |
prepare
Prepared statements.
public prepare(string $sql, ?string $name = null): \Hazaar\DBI\Result
Parameters:
Parameter | Type | Description |
---|---|---|
$sql | string | |
$name | ?string |
execute
public execute(string $name, array $inputParameters): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$name | string | |
$inputParameters | array |
getPreparedStatements
public getPreparedStatements(): \PDOStatement[]
listPreparedStatements
public listPreparedStatements(): string[]
getSchemaManager
Returns an instance of the Hazaar\DBI\Schema\Manager for managing database schema versions.
public getSchemaManager(): \Hazaar\DBI\Schema\Manager
insert
Perform and "upsert".
public insert(string $tableName, mixed $fields, mixed $returning = null, null|array|string $conflictTarget = null, array $conflictUpdate = null, ?\Hazaar\DBI\Table $table = null): array|false|int
An upsert is an INSERT, that when it fails, columns can be updated in the existing row.
Parameters:
Parameter | Type | Description |
---|---|---|
$tableName | string | the table to insert a record into |
$fields | mixed | the fields to be inserted |
$returning | mixed | a column to return when the row is inserted (usually the primary key) |
$conflictTarget | null|array|string | the column(s) to check for a conflict. If the conflict is found, the row will be updated. |
$conflictUpdate | array | |
$table | ?\Hazaar\DBI\Table |
update
public update(string $tableName, mixed $fields, mixed $criteria = [], string[] $from = [], mixed $returning = [], string[] $tables = []): array|false|int
Parameters:
Parameter | Type | Description |
---|---|---|
$tableName | string | |
$fields | mixed | |
$criteria | mixed | |
$from | string[] | |
$returning | mixed | |
$tables | string[] |
encrypt
public encrypt(string $table, mixed& $data): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$table | string | |
$data | mixed |
errorException
public errorException(?string $msg = null): \Exception
Parameters:
Parameter | Type | Description |
---|---|---|
$msg | ?string |
parseSQL
Parse an SQL query into a DBI Table query so that it can be manipulated.
public parseSQL(string $sql): \Hazaar\DBI\Table\SQL
Parameters:
Parameter | Type | Description |
---|---|---|
$sql | string | The SQL query to parse |
grant
Grant privileges on a table to a user.
public grant(string $table, string $user, string[]|string $privileges = 'ALL'): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$table | string | the name of the table to grant privileges on |
$user | string | The name of the user who is being given the privileges |
$privileges | string[]|string | One or more privileges being applied. Example: (string)'ALL' and (array)['INSERT', 'UPDATE', 'DELETE'] are both valid. |
reconfigure
private reconfigure(bool $reconnect = false): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$reconnect | bool |
Automatically generated on 2024-11-14