Interface ConnectionInterface
This interface defines the methods you can depend on in a connection.
Method Summary
-
config() public
Get the configuration data used to create the connection.
-
configName() public
Get the configuration name for this connection.
-
disableConstraints() public
Run an operation with constraints disabled.
-
disableQueryLogging() public
Disable query logging
-
enableQueryLogging() public
Enable/disable query logging
-
execute() public @method
Executes a query using
$paramsfor interpolating values and $types as a hint for each those params. {@see \Cake\Database\Connnection::execute()} -
getCacher() public
Get a cacher.
-
getDriver() public @method
Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}
-
getLogger() public
Gets the current logger object.
-
getSchemaCollection() public @method
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
-
isQueryLoggingEnabled() public
Check if query logging is enabled.
-
prepare() public @method
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
-
query() public @method
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
-
setCacher() public
Set a cacher.
-
setLogger() public @method
Set the current logger. {@see \Cake\Database\Connnection::setLogger()}
-
supportsDynamicConstraints() public @method
Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}
-
transactional() public
Executes a callable function inside a transaction, if any exception occurs while executing the passed callable, the transaction will be rolled back If the result of the callable function is
false, the transaction will also be rolled back. Otherwise, the transaction is committed after executing the callback.
Method Detail
config() ¶ public
config(): array<string, mixed>
Get the configuration data used to create the connection.
Returns
array<string, mixed>configName() ¶ public
configName(): string
Get the configuration name for this connection.
Returns
stringdisableConstraints() ¶ public
disableConstraints(callable $callback): mixed
Run an operation with constraints disabled.
Constraints should be re-enabled after the callback succeeds/fails.
Example:
$connection->disableConstraints(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
Parameters
-
callable$callback The callback to execute within a transaction.
Returns
mixedThrows
ExceptionWill re-throw any exception raised in $callback after rolling back the transaction.
enableQueryLogging() ¶ public
enableQueryLogging(bool $enable = true): $this
Enable/disable query logging
Parameters
-
bool$enable optional Enable/disable query logging
Returns
$thisexecute() ¶ public @method
execute(mixed $query, mixed $params = [], array $types = []): Cake\Database\StatementInterface
Executes a query using
$params for interpolating values and $types as a hint for each those params.
{@see \Cake\Database\Connnection::execute()}
Parameters
-
$query -
$params optional -
array$types optional
Returns
Cake\Database\StatementInterfacegetCacher() ¶ public
getCacher(): Psr\SimpleCache\CacheInterface
Get a cacher.
Returns
Psr\SimpleCache\CacheInterfacegetDriver() ¶ public @method
getDriver(): object
Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}
Returns
objectgetLogger() ¶ public
getLogger(): Psr\Log\LoggerInterface
Gets the current logger object.
Returns
Psr\Log\LoggerInterfacegetSchemaCollection() ¶ public @method
getSchemaCollection(): Cake\Database\Schema\Collection
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
Returns
Cake\Database\Schema\CollectionisQueryLoggingEnabled() ¶ public
isQueryLoggingEnabled(): bool
Check if query logging is enabled.
Returns
boolprepare() ¶ public @method
prepare(mixed $sql): Cake\Database\StatementInterface
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
Parameters
-
$sql
Returns
Cake\Database\StatementInterfacequery() ¶ public @method
query(string $sql): Cake\Database\StatementInterface
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
Parameters
-
string$sql
Returns
Cake\Database\StatementInterfacesetCacher() ¶ public
setCacher(Psr\SimpleCache\CacheInterface $cacher): $this
Set a cacher.
Parameters
-
Psr\SimpleCache\CacheInterface$cacher Cacher object
Returns
$thissetLogger() ¶ public @method
setLogger(LoggerInterface $logger): void
Set the current logger. {@see \Cake\Database\Connnection::setLogger()}
Parameters
-
LoggerInterface$logger
Returns
voidsupportsDynamicConstraints() ¶ public @method
supportsDynamicConstraints(): bool
Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}
Returns
booltransactional() ¶ public
transactional(callable $callback): mixed
Executes a callable function inside a transaction, if any exception occurs
while executing the passed callable, the transaction will be rolled back
If the result of the callable function is false, the transaction will
also be rolled back. Otherwise, the transaction is committed after executing
the callback.
The callback will receive the connection instance as its first argument.
Example:
$connection->transactional(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
Parameters
-
callable$callback The callback to execute within a transaction.
Returns
mixedThrows
ExceptionWill re-throw any exception raised in $callback after rolling back the transaction.