ConnectionInterface
extends
LoggerAwareInterface
in
This interface defines the methods you can depend on in a connection.
Table of Contents
Methods
- config() : array<string, mixed>
- Get the configuration data used to create the connection.
- configName() : string
- Get the configuration name for this connection.
- disableConstraints() : mixed
- Run an operation with constraints disabled.
- disableQueryLogging() : $this
- Disable query logging
- enableQueryLogging() : $this
- Enable/disable query logging
- getCacher() : CacheInterface
- Get a cacher.
- getLogger() : LoggerInterface
- Gets the current logger object.
- isQueryLoggingEnabled() : bool
- Check if query logging is enabled.
- setCacher() : $this
- Set a cacher.
- setLogger() : void
- Sets a logger instance on the object.
- transactional() : 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.
Methods
config()
Get the configuration data used to create the connection.
public
config() : array<string, mixed>
Return values
array<string, mixed>configName()
Get the configuration name for this connection.
public
configName() : string
Return values
stringdisableConstraints()
Run an operation with constraints disabled.
public
disableConstraints(callable $callback) : mixed
Constraints should be re-enabled after the callback succeeds/fails.
Example:
$connection->disableConstraints(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
Parameters
- $callback : callable
-
The callback to execute within a transaction.
Tags
Return values
mixed —The return value of the callback.
disableQueryLogging()
Disable query logging
public
disableQueryLogging() : $this
Return values
$thisenableQueryLogging()
Enable/disable query logging
public
enableQueryLogging([bool $enable = true ]) : $this
Parameters
- $enable : bool = true
-
Enable/disable query logging
Return values
$thisgetCacher()
Get a cacher.
public
getCacher() : CacheInterface
Return values
CacheInterface —$cacher Cacher object
getLogger()
Gets the current logger object.
public
getLogger() : LoggerInterface
Return values
LoggerInterface —logger instance
isQueryLoggingEnabled()
Check if query logging is enabled.
public
isQueryLoggingEnabled() : bool
Return values
boolsetCacher()
Set a cacher.
public
setCacher(CacheInterface $cacher) : $this
Parameters
- $cacher : CacheInterface
-
Cacher object
Return values
$thissetLogger()
Sets a logger instance on the object.
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
transactional()
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.
public
transactional(callable $callback) : mixed
The callback will receive the connection instance as its first argument.
Example:
$connection->transactional(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
Parameters
- $callback : callable
-
The callback to execute within a transaction.
Tags
Return values
mixed —The return value of the callback.