Fr3nch13/CakePHP Utilities

ConnectionInterface extends LoggerAwareInterface

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
string

disableConstraints()

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
throws
Exception

Will re-throw any exception raised in $callback after rolling back the transaction.

Return values
mixed

The return value of the callback.

disableQueryLogging()

Disable query logging

public disableQueryLogging() : $this
Return values
$this

enableQueryLogging()

Enable/disable query logging

public enableQueryLogging([bool $enable = true ]) : $this
Parameters
$enable : bool = true

Enable/disable query logging

Return values
$this

isQueryLoggingEnabled()

Check if query logging is enabled.

public isQueryLoggingEnabled() : bool
Return values
bool

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
throws
Exception

Will re-throw any exception raised in $callback after rolling back the transaction.

Return values
mixed

The return value of the callback.


        
On this page

Search results