Class Driver
Represents a database driver containing all specificities for a database engine including its SQL dialect.
Constants
Property Summary
- 
        $_autoQuoting protectedboolIndicates whether the driver is doing automatic identifier quoting for all queries 
- 
        $_baseConfig protectedarray<string, mixed>Base configuration that is merged into the user supplied configuration data. 
- 
        $_config protectedarray<string, mixed>Configuration data. 
- 
        $_endQuote protectedstringString used to end a database identifier quoting to make it safe 
- 
        $_schemaDialect protectedCake\Database\Schema\SchemaDialectThe schema dialect for this driver 
- 
        $_startQuote protectedstringString used to start a database identifier quoting to make it safe 
- 
        $_version protectedstring|nullThe server version 
- 
        $connectRetries protectedintThe last number of connection retry attempts. 
- 
        $logQueries protectedboolWhether to log queries generated during this connection. 
- 
        $logger protected?LoggerInterfaceThe logger instance. 
- 
        $pdo protectedPDO|nullInstance of PDO. 
- 
        $quoter protectedCake\Database\IdentifierQuoter|nullIdentifier quoter 
Method Summary
- 
          __construct() publicConstructor 
- 
          __debugInfo() publicReturns an array that can be used to describe the internal state of this object. 
- 
          __destruct() publicDestructor 
- 
          _deleteQueryTranslator() protectedApply translation steps to delete queries. 
- 
          _expressionTranslators() protectedReturns an associative array of methods that will transform Expression objects to conform with the specific SQL dialect. Keys are class names and values a method in this class. 
- 
          _insertQueryTranslator() protectedApply translation steps to insert queries. 
- 
          _removeAliasesFromConditions() protectedRemoves aliases from the WHEREclause of a query.
- 
          _selectQueryTranslator() protectedApply translation steps to select queries. 
- 
          _transformDistinct() protectedReturns the passed query after rewriting the DISTINCT clause, so that drivers that do not support the "ON" part can provide the actual way it should be done 
- 
          _updateQueryTranslator() protectedApply translation steps to update queries. 
- 
          beginTransaction() publicStarts a transaction. 
- 
          commitTransaction() publicCommits a transaction. 
- 
          compileQuery() publicTransforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string. 
- 
          config() publicGet the configuration data used to create the driver. 
- 
          connect() abstract publicEstablishes a connection to the database server. 
- 
          createLogger() protectedCreate logger instance. 
- 
          createPdo() protectedEstablishes a connection to the database server 
- 
          createQueryException() protectedCreate a QueryException from a PDOException 
- 
          disableAutoQuoting() publicDisable auto quoting of identifiers in queries. 
- 
          disableForeignKeySQL() abstract publicGet the SQL for disabling foreign keys. 
- 
          disableQueryLogging() publicDisable query logging. 
- 
          disconnect() publicDisconnects from database server. 
- 
          enableAutoQuoting() publicSets whether this driver should automatically quote identifiers in queries. 
- 
          enableForeignKeySQL() abstract publicGet the SQL for enabling foreign keys. 
- 
          enableQueryLogging() publicEnable query logging. 
- 
          enabled() abstract publicReturns whether php is able to use this driver for connecting to database. 
- 
          exec() publicExecute the SQL query using the internal PDO instance. 
- 
          execute() publicExecutes a query using $params for interpolating values and $types as a hint for each those params. 
- 
          executeStatement() protectedExecute the statement and log the query string. 
- 
          getLogger() publicGet the logger instance. 
- 
          getMaxAliasLength() publicReturns the maximum alias length allowed. 
- 
          getPdo() protectedGet the PDO connection instance. 
- 
          getResultSetDecorators() protectedReturns the decorators to be applied to the result set incase of a SelectQuery. 
- 
          getRole() publicReturns the connection role this driver performs. 
- 
          inTransaction() publicReturns whether a transaction is active for connection. 
- 
          isAutoQuotingEnabled() publicReturns whether this driver should automatically quote identifiers in queries. 
- 
          isConnected() publicChecks whether the driver is connected. 
- 
          lastInsertId() publicReturns last id generated for a table or sequence in database. 
- 
          log() publicLogs a message or query using the configured logger object. 
- 
          newCompiler() public
- 
          newTableSchema() publicConstructs new TableSchema. 
- 
          prepare() publicPrepares a sql statement to be executed. 
- 
          quote() publicQuotes a database value. 
- 
          quoteIdentifier() publicQuotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words 
- 
          quoter() publicGet identifier quoter instance. 
- 
          releaseSavePointSQL() publicReturns a SQL snippet for releasing a previously created save point 
- 
          rollbackSavePointSQL() publicReturns a SQL snippet for rollbacking a previously created save point 
- 
          rollbackTransaction() publicRollbacks a transaction. 
- 
          run() publicExecutes the provided query after compiling it for the specific driver dialect and returns the executed Statement object. 
- 
          savePointSQL() publicReturns a SQL snippet for creating a new transaction savepoint 
- 
          schema() publicReturns the schema name that's being used. 
- 
          schemaDialect() abstract publicGet the schema dialect. 
- 
          schemaValue() publicEscapes values for use in schema definitions. 
- 
          setLogger() publicSets a logger. 
- 
          supports() abstract publicReturns whether the driver supports the feature. 
- 
          transformQuery() protectedTransform the query to accommodate any specificities of the SQL dialect in use. 
- 
          version() publicReturns connected server version. 
Method Detail
__construct() ¶ public
__construct(array<string, mixed> $config = [])Constructor
Parameters
- 
                array<string, mixed>$config optional
- The configuration for the driver. 
Throws
InvalidArgumentException__debugInfo() ¶ public
__debugInfo(): array<string, mixed>Returns an array that can be used to describe the internal state of this object.
Returns
array<string, mixed>_deleteQueryTranslator() ¶ protected
_deleteQueryTranslator(Cake\Database\Query\DeleteQuery $query): Cake\Database\Query\DeleteQueryApply translation steps to delete queries.
Chops out aliases on delete query conditions as most database dialects do not support aliases in delete queries. This also removes aliases in table names as they frequently don't work either.
We are intentionally not supporting deletes with joins as they have even poorer support.
Parameters
- 
                Cake\Database\Query\DeleteQuery$query
- The query to translate 
Returns
Cake\Database\Query\DeleteQueryThe modified query
_expressionTranslators() ¶ protected
_expressionTranslators(): array<class-string, string>Returns an associative array of methods that will transform Expression objects to conform with the specific SQL dialect. Keys are class names and values a method in this class.
Returns
array<class-string, string>_insertQueryTranslator() ¶ protected
_insertQueryTranslator(Cake\Database\Query\InsertQuery $query): Cake\Database\Query\InsertQueryApply translation steps to insert queries.
Parameters
- 
                Cake\Database\Query\InsertQuery$query
- The query to translate 
Returns
Cake\Database\Query\InsertQueryThe modified query
_removeAliasesFromConditions() ¶ protected
_removeAliasesFromConditions(Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQuery $query): Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQueryRemoves aliases from the WHERE clause of a query.
Templates
              T
               of (\Cake\Database\Query\UpdateQuery | \Cake\Database\Query\DeleteQuery)                            Parameters
- 
                Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQuery$query
- The query to process. 
Returns
Cake\Database\Query\UpdateQuery|Cake\Database\Query\DeleteQueryThe modified query.
Throws
Cake\Database\Exception\DatabaseExceptionIn case the processed query contains any joins, as removing aliases from the conditions can break references to the joined tables.
_selectQueryTranslator() ¶ protected
_selectQueryTranslator(Cake\Database\Query\SelectQuery<mixed> $query): Cake\Database\Query\SelectQuery<mixed>Apply translation steps to select queries.
Parameters
- 
                Cake\Database\Query\SelectQuery<mixed>$query
- The query to translate 
Returns
Cake\Database\Query\SelectQuery<mixed>The modified query
_transformDistinct() ¶ protected
_transformDistinct(Cake\Database\Query\SelectQuery<mixed> $query): Cake\Database\Query\SelectQuery<mixed>Returns the passed query after rewriting the DISTINCT clause, so that drivers that do not support the "ON" part can provide the actual way it should be done
Parameters
- 
                Cake\Database\Query\SelectQuery<mixed>$query
- The query to be transformed 
Returns
Cake\Database\Query\SelectQuery<mixed>_updateQueryTranslator() ¶ protected
_updateQueryTranslator(Cake\Database\Query\UpdateQuery $query): Cake\Database\Query\UpdateQueryApply translation steps to update queries.
Chops out aliases on update query conditions as not all database dialects do support aliases in update queries.
Just like for delete queries, joins are currently not supported for update queries.
Parameters
- 
                Cake\Database\Query\UpdateQuery$query
- The query to translate 
Returns
Cake\Database\Query\UpdateQueryThe modified query
beginTransaction() ¶ public
beginTransaction(): boolStarts a transaction.
Returns
boolTrue on success, false otherwise.
commitTransaction() ¶ public
commitTransaction(): boolCommits a transaction.
Returns
boolTrue on success, false otherwise.
compileQuery() ¶ public
compileQuery(Cake\Database\Query $query, Cake\Database\ValueBinder $binder): stringTransforms the passed query to this Driver's dialect and returns an instance of the transformed query and the full compiled SQL string.
Parameters
- 
                Cake\Database\Query$query
- The query to compile. 
- 
                Cake\Database\ValueBinder$binder
- The value binder to use. 
Returns
stringThe compiled SQL.
config() ¶ public
config(): array<string, mixed>Get the configuration data used to create the driver.
Returns
array<string, mixed>connect() ¶ abstract public
connect(): voidEstablishes a connection to the database server.
Returns
voidThrows
Cake\Database\Exception\MissingConnectionExceptionIf database connection could not be established.
createLogger() ¶ protected
createLogger(string|null $className): Psr\Log\LoggerInterfaceCreate logger instance.
Parameters
- 
                string|null$className
- Logger's class name 
Returns
Psr\Log\LoggerInterfacecreatePdo() ¶ protected
createPdo(string $dsn, array<string, mixed> $config): PDOEstablishes a connection to the database server
Parameters
- 
                string$dsn
- A Driver-specific PDO-DSN 
- 
                array<string, mixed>$config
- configuration to be used for creating connection 
Returns
PDOcreateQueryException() ¶ protected
createQueryException(PDOException $exception, Cake\Database\StatementInterface $statement, array|null $params = null): Cake\Database\Exception\QueryExceptionCreate a QueryException from a PDOException
Parameters
- 
                PDOException$exception
- 
                Cake\Database\StatementInterface$statement
- 
                array|null$params optional
Returns
Cake\Database\Exception\QueryExceptiondisableAutoQuoting() ¶ public
disableAutoQuoting(): $thisDisable auto quoting of identifiers in queries.
Returns
$thisdisableForeignKeySQL() ¶ abstract public
disableForeignKeySQL(): stringGet the SQL for disabling foreign keys.
Returns
stringenableAutoQuoting() ¶ public
enableAutoQuoting(bool $enable = true): $thisSets whether this driver should automatically quote identifiers in queries.
Parameters
- 
                bool$enable optional
- Whether to enable auto quoting 
Returns
$thisenableForeignKeySQL() ¶ abstract public
enableForeignKeySQL(): stringGet the SQL for enabling foreign keys.
Returns
stringenabled() ¶ abstract public
enabled(): boolReturns whether php is able to use this driver for connecting to database.
Returns
boolTrue if it is valid to use this driver.
exec() ¶ public
exec(string $sql): int|falseExecute the SQL query using the internal PDO instance.
Parameters
- 
                string$sql
- SQL query. 
Returns
int|falseexecute() ¶ public
execute(string $sql, array $params = [], array $types = []): Cake\Database\StatementInterfaceExecutes a query using $params for interpolating values and $types as a hint for each those params.
Parameters
- 
                string$sql
- SQL to be executed and interpolated with $params 
- 
                array$params optional
- List or associative array of params to be interpolated in $sql as values. 
- 
                array$types optional
- List or associative array of types to be used for casting values in query. 
Returns
Cake\Database\StatementInterfaceExecuted statement
executeStatement() ¶ protected
executeStatement(Cake\Database\StatementInterface $statement, array|null $params = null): voidExecute the statement and log the query string.
Parameters
- 
                Cake\Database\StatementInterface$statement
- Statement to execute. 
- 
                array|null$params optional
- List of values to be bound to query. 
Returns
voidgetLogger() ¶ public
getLogger(): Psr\Log\LoggerInterface|nullGet the logger instance.
Returns
Psr\Log\LoggerInterface|nullgetMaxAliasLength() ¶ public
getMaxAliasLength(): int|nullReturns the maximum alias length allowed.
This can be different from the maximum identifier length for columns.
Returns
int|nullMaximum alias length or null if no limit
getResultSetDecorators() ¶ protected
getResultSetDecorators(Cake\Database\Query|string $query): array<Closure>Returns the decorators to be applied to the result set incase of a SelectQuery.
Parameters
- 
                Cake\Database\Query|string$query
- The query to be decorated. 
Returns
array<Closure>getRole() ¶ public
getRole(): stringReturns the connection role this driver performs.
Returns
stringinTransaction() ¶ public
inTransaction(): boolReturns whether a transaction is active for connection.
Returns
boolisAutoQuotingEnabled() ¶ public
isAutoQuotingEnabled(): boolReturns whether this driver should automatically quote identifiers in queries.
Returns
boollastInsertId() ¶ public
lastInsertId(string|null $table = null): stringReturns last id generated for a table or sequence in database.
Parameters
- 
                string|null$table optional
- table name or sequence to get last insert value from. 
Returns
stringlog() ¶ public
log(Stringable|string $message, array $context = []): boolLogs a message or query using the configured logger object.
Parameters
- 
                Stringable|string$message
- Message string or query. 
- 
                array$context optional
- Logging context. 
Returns
boolTrue if message was logged.
newCompiler() ¶ public
newCompiler(): Cake\Database\QueryCompilerReturns
Cake\Database\QueryCompilernewTableSchema() ¶ public
newTableSchema(string $table, array<string, mixed> $columns = []): Cake\Database\Schema\TableSchemaInterfaceConstructs new TableSchema.
Parameters
- 
                string$table
- The table name. 
- 
                array<string, mixed>$columns optional
- The list of columns for the schema. 
Returns
Cake\Database\Schema\TableSchemaInterfaceprepare() ¶ public
prepare(Cake\Database\Query|string $query): Cake\Database\StatementInterfacePrepares a sql statement to be executed.
Parameters
- 
                Cake\Database\Query|string$query
- The query to turn into a prepared statement. 
Returns
Cake\Database\StatementInterfacequote() ¶ public
quote(string $value): stringQuotes a database value.
This makes values safe for concatenation in SQL queries.
Using this method is not recommended. You should use execute()
instead, as it uses prepared statements which are safer than
string concatenation.
This method should only be used for queries that do not support placeholders.
Parameters
- 
                string$value
- The value to quote. 
Returns
stringquoteIdentifier() ¶ public
quoteIdentifier(string $identifier): stringQuotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words
Parameters
- 
                string$identifier
- The identifier to quote. 
Returns
stringquoter() ¶ public
quoter(): Cake\Database\IdentifierQuoterGet identifier quoter instance.
Returns
Cake\Database\IdentifierQuoterreleaseSavePointSQL() ¶ public
releaseSavePointSQL(string|int $name): stringReturns a SQL snippet for releasing a previously created save point
Parameters
- 
                string|int$name
- save point name 
Returns
stringrollbackSavePointSQL() ¶ public
rollbackSavePointSQL(string|int $name): stringReturns a SQL snippet for rollbacking a previously created save point
Parameters
- 
                string|int$name
- save point name 
Returns
stringrollbackTransaction() ¶ public
rollbackTransaction(): boolRollbacks a transaction.
Returns
boolTrue on success, false otherwise.
run() ¶ public
run(Cake\Database\Query $query): Cake\Database\StatementInterfaceExecutes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
Parameters
- 
                Cake\Database\Query$query
- The query to be executed. 
Returns
Cake\Database\StatementInterfaceExecuted statement
savePointSQL() ¶ public
savePointSQL(string|int $name): stringReturns a SQL snippet for creating a new transaction savepoint
Parameters
- 
                string|int$name
- save point name 
Returns
stringschemaDialect() ¶ abstract public
schemaDialect(): Cake\Database\Schema\SchemaDialectGet the schema dialect.
Used by {@link \Cake\Database\Schema} package to reflect schema and generate schema.
If all the tables that use this Driver specify their own schemas, then this may return null.
Returns
Cake\Database\Schema\SchemaDialectschemaValue() ¶ public
schemaValue(mixed $value): stringEscapes values for use in schema definitions.
Parameters
- 
                mixed$value
- The value to escape. 
Returns
stringString for use in schema definitions.
setLogger() ¶ public
setLogger(LoggerInterface $logger): voidSets a logger.
Parameters
- 
                LoggerInterface$logger
Returns
voidsupports() ¶ abstract public
supports(Cake\Database\DriverFeatureEnum $feature): boolReturns whether the driver supports the feature.
Should return false for unknown features.
Parameters
- 
                Cake\Database\DriverFeatureEnum$feature
- Driver feature 
Returns
booltransformQuery() ¶ protected
transformQuery(Cake\Database\Query $query): Cake\Database\QueryTransform the query to accommodate any specificities of the SQL dialect in use.
It will also quote the identifiers if auto quoting is enabled.
Parameters
- 
                Cake\Database\Query$query
- Query to transform. 
Returns
Cake\Database\QueryProperty Detail
$_autoQuoting ¶ protected
Indicates whether the driver is doing automatic identifier quoting for all queries
Type
bool$_baseConfig ¶ protected
Base configuration that is merged into the user supplied configuration data.
Type
array<string, mixed>$_schemaDialect ¶ protected
The schema dialect for this driver
Type
Cake\Database\Schema\SchemaDialect$_startQuote ¶ protected
String used to start a database identifier quoting to make it safe
Type
string