Interface ConnectionInterface
This interface defines the methods you can depend on in a connection.
Method Summary
- execute() public
Executes a query using
$params
for interpolating values and $types as a hint for each those params. {@see \Cake\Database\Connnection::execute()} - getSchemaCollection() public
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
- newQuery() public
Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}
- prepare() public
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
- query() public
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
- supportsDynamicConstraints() public
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()
Get the configuration data used to create the connection.
Returns
array
configName() public
configName()
Get the configuration name for this connection.
Returns
string
disableConstraints() public
disableConstraints(callable $callback)
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
mixed
The return value of the callback.
Throws
Exception
Will re-throw any exception raised in $callback after rolling back the transaction.
disableQueryLogging() public
disableQueryLogging()
Disable query logging
Returns
$this
enableQueryLogging() public
enableQueryLogging(bool $enable)
Enable/disable query logging
Parameters
-
bool
$enable optional Enable/disable query logging
Returns
$this
execute() public
execute(mixed $query, mixed $params, array $types = [])
Executes a query using $params
for interpolating values and $types as a hint for each those params. {@see \Cake\Database\Connnection::execute()}
Parameters
-
mixed
$query -
mixed
$params -
array
$types = []
getCacher() public
getCacher()
Get a cacher.
Returns
\Psr\SimpleCache\CacheInterface
$cacher Cacher object
getDriver() public
getDriver()
Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}
getLogger() public
getLogger()
Gets the current logger object.
Returns
\Psr\Log\LoggerInterface
logger instance
getSchemaCollection() public
getSchemaCollection()
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
isQueryLoggingEnabled() public
isQueryLoggingEnabled()
Check if query logging is enabled.
Returns
bool
newQuery() public
newQuery()
Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}
prepare() public
prepare(mixed $sql)
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
Parameters
-
mixed
$sql
query() public
query(string $sql)
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
Parameters
-
string
$sql
setCacher() public
setCacher(\Psr\SimpleCache\CacheInterface $cacher)
Set a cacher.
Parameters
-
\Psr\SimpleCache\CacheInterface
$cacher Cacher object
Returns
$this
setLogger() public
setLogger(mixed $logger)
Set the current logger. {@see \Cake\Database\Connnection::setLogger()}
Parameters
-
mixed
$logger
supportsDynamicConstraints() public
supportsDynamicConstraints()
Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}
transactional() public
transactional(callable $callback)
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
mixed
The return value of the callback.
Throws
Exception
Will re-throw any exception raised in $callback after rolling back the transaction.
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/interface-Cake.Datasource.ConnectionInterface.html