This interface defines the methods you can depend on in a connection.
Get the configuration data used to create the connection.
Get the configuration name for this connection.
Run an operation with constraints disabled.
Disable query logging
Enable/disable query logging
Executes a query using $params
for interpolating values and $types as a hint for each those params. {@see \Cake\Database\Connnection::execute()}
Get a cacher.
Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}
Gets the current logger object.
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
Check if query logging is enabled.
Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
Set a cacher.
Set the current logger. {@see \Cake\Database\Connnection::setLogger()}
Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}
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.
config(): array<string, mixed>
Get the configuration data used to create the connection.
array<string, mixed>
configName(): string
Get the configuration name for this connection.
string
disableConstraints(callable $callback): mixed
Run an operation with constraints disabled.
Constraints should be re-enabled after the callback succeeds/fails.
$connection->disableConstraints(function ($connection) { $connection->newQuery()->delete('users')->execute(); });
callable
$callback The callback to execute within a transaction.
mixed
Exception
disableQueryLogging(): $this
Disable query logging
$this
enableQueryLogging(bool $enable = true): $this
Enable/disable query logging
bool
$enable optional Enable/disable query logging
$this
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()}
array
$types optional Cake\Database\StatementInterface
getCacher(): Psr\SimpleCache\CacheInterface
Get a cacher.
Psr\SimpleCache\CacheInterface
getDriver(): object
Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}
object
getLogger(): Psr\Log\LoggerInterface
Gets the current logger object.
Psr\Log\LoggerInterface
getSchemaCollection(): Cake\Database\Schema\Collection
Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}
Cake\Database\Schema\Collection
isQueryLoggingEnabled(): bool
Check if query logging is enabled.
bool
newQuery(): Cake\Database\Query
Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}
Cake\Database\Query
prepare(mixed $sql): Cake\Database\StatementInterface
Prepares a SQL statement to be executed. {@see \Cake\Database\Connnection::prepare()}
Cake\Database\StatementInterface
query(string $sql): Cake\Database\StatementInterface
Executes a SQL statement and returns the Statement object as result. {@see \Cake\Database\Connnection::query()}
string
$sql Cake\Database\StatementInterface
setCacher(Psr\SimpleCache\CacheInterface $cacher): $this
Set a cacher.
Psr\SimpleCache\CacheInterface
$cacher Cacher object
$this
setLogger(LoggerInterface $logger): void
Set the current logger. {@see \Cake\Database\Connnection::setLogger()}
LoggerInterface
$logger void
supportsDynamicConstraints(): bool
Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}
bool
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.
$connection->transactional(function ($connection) { $connection->newQuery()->delete('users')->execute(); });
callable
$callback The callback to execute within a transaction.
mixed
Exception
© 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.4/interface-Cake.Datasource.ConnectionInterface.html