CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.4 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.4
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
      • Exception
      • Locator
      • Paging
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Interface ConnectionInterface

This interface defines the methods you can depend on in a connection.

Namespace: Cake\Datasource

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 $params for 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.

  • newQuery() public @method

    Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}

  • 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
string

disableConstraints() ¶ 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
mixed
Throws
Exception
Will re-throw any exception raised in $callback after rolling back the transaction.

disableQueryLogging() ¶ public

disableQueryLogging(): $this

Disable query logging

Returns
$this

enableQueryLogging() ¶ public

enableQueryLogging(bool $enable = true): $this

Enable/disable query logging

Parameters
bool $enable optional

Enable/disable query logging

Returns
$this

execute() ¶ 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\StatementInterface

getCacher() ¶ public

getCacher(): Psr\SimpleCache\CacheInterface

Get a cacher.

Returns
Psr\SimpleCache\CacheInterface

getDriver() ¶ public @method

getDriver(): object

Gets the driver instance. {@see \Cake\Database\Connnection::getDriver()}

Returns
object

getLogger() ¶ public

getLogger(): Psr\Log\LoggerInterface

Gets the current logger object.

Returns
Psr\Log\LoggerInterface

getSchemaCollection() ¶ public @method

getSchemaCollection(): Cake\Database\Schema\Collection

Gets a Schema\Collection object for this connection. {@see \Cake\Database\Connnection::getSchemaCollection()}

Returns
Cake\Database\Schema\Collection

isQueryLoggingEnabled() ¶ public

isQueryLoggingEnabled(): bool

Check if query logging is enabled.

Returns
bool

newQuery() ¶ public @method

newQuery(): Cake\Database\Query

Create a new Query instance for this connection. {@see \Cake\Database\Connnection::newQuery()}

Returns
Cake\Database\Query

prepare() ¶ 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\StatementInterface

query() ¶ 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\StatementInterface

setCacher() ¶ public

setCacher(Psr\SimpleCache\CacheInterface $cacher): $this

Set a cacher.

Parameters
Psr\SimpleCache\CacheInterface $cacher

Cacher object

Returns
$this

setLogger() ¶ public @method

setLogger(LoggerInterface $logger): void

Set the current logger. {@see \Cake\Database\Connnection::setLogger()}

Parameters
LoggerInterface $logger
Returns
void

supportsDynamicConstraints() ¶ public @method

supportsDynamicConstraints(): bool

Returns whether the driver supports adding or dropping constraints to already created tables. {@see \Cake\Database\Connnection::supportsDynamicConstraints()}

Returns
bool

transactional() ¶ 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
mixed
Throws
Exception
Will re-throw any exception raised in $callback after rolling back the transaction.
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs