Represents a connection with a database server.
$_config protected array$_driver protected Driver object, responsible for creating the real connection and provide specific SQL dialect.
$_logQueries protected boolean$_logger protected Cake\Database\Log\QueryLogger|null$_schemaCollection protected $_transactionLevel protected integer$_transactionStarted protected boolean$_useSavePoints protected booleanWhether this connection can and should use savepoints for nested transactions.
$nestedTransactionRollbackException protected NestedTransactionRollbackException object instance, will be stored if the rollback method is called in some nested transaction.
Returns an array that can be used to describe the internal state of this object.
Returns a new statement object that will log the activity for the passed original statement instance.
Compiles a Query object into a SQL string according to the dialect for this connection's driver
Sets the driver instance. If a string is passed it will be treated as a class name and will be instantiated.
Executes a query using $params for interpolating values and $types as a hint for each those params.
Get the retry wrapper object that is allows recovery from server disconnects while performing certain database actions, such as executing a query.
Sets the logger object instance. When called with no arguments it returns the currently setup logger instance.
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
Sets the driver instance. If a string is passed it will be treated as a class name and will be instantiated.
Returns whether the driver supports adding or dropping constraints to already created tables.
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.
Returns whether this connection is using savepoints for nested transactions If a boolean is passed as argument it will enable/disable the usage of savepoints only if driver the allows it.
__construct( array $config )
Constructor.
$config __debugInfo( )
Returns an array that can be used to describe the internal state of this object.
__destruct( )
Destructor
Disconnects the driver to release the connection.
_newLogger( Cake\Database\StatementInterface $statement )
Returns a new statement object that will log the activity for the passed original statement instance.
Cake\Database\StatementInterface $statement cacheMetadata( boolean|string $cache )
Enables or disables metadata caching for this connection
Changing this setting will not modify existing schema collections objects.
$cache Either boolean false to disable metadata caching, or true to use _cake_model_ or the name of the cache config to use.
commit( )
Commits current transaction.
compileQuery( Cake\Database\Query $query , Cake\Database\ValueBinder $generator )
Compiles a Query object into a SQL string according to the dialect for this connection's driver
Cake\Database\Query $query $generator config( )
Get the configuration data used to create the connection.
Cake\Datasource\ConnectionInterface::config() configName( )
Get the configuration name for this connection.
Cake\Datasource\ConnectionInterface::configName() connect( )
Connects to the configured database.
Cake\Database\Exception\MissingConnectionExceptioncreateSavePoint( string $name )
Creates a new save point for nested transactions.
$name delete( string $table , array $conditions = [] , array $types = [] )
Executes a DELETE statement on the specified table.
$table $conditions optional [] $types optional [] Cake\Database\StatementInterfacedisableConstraints( callable $callback )
Run an operation with constraints disabled.
$connection->disableConstraints(function ($connection) {
$connection->newQuery()->delete('users')->execute();
}); $callback Will re-throw any exception raised in $callback after rolling back the transaction.
Cake\Datasource\ConnectionInterface::disableConstraints() disableForeignKeys( )
Run driver specific SQL to disable foreign key checks.
disableSavePoints( )
Disables the usage of savepoints.
driver( Cake\Database\Driver|string|null $driver = null , array $config = [] )
Sets the driver instance. If a string is passed it will be treated as a class name and will be instantiated.
If no params are passed it will return the current driver instance.
Cake\Database\Driver|string|null $driver optional null $config optional [] Cake\Database\DriverCake\Database\Exception\MissingDriverExceptionCake\Database\Exception\MissingExtensionExceptionenableForeignKeys( )
Run driver specific SQL to enable foreign key checks.
enableQueryLogging( boolean $value )
Enable/disable query logging
$value enableSavePoints( boolean $enable )
Enables/disables the usage of savepoints, enables only if driver the allows it.
If you are trying to enable this feature, make sure you check the return value of this function to verify it was enabled successfully.
$connection->enableSavePoints(true) Returns true if drivers supports save points, false otherwise $connection->enableSavePoints(false) Disables usage of savepoints and returns false
$enable execute( string $query , array $params = [] , array $types = [] )
Executes a query using $params for interpolating values and $types as a hint for each those params.
$query $params optional [] $types optional [] Cake\Database\StatementInterfacegetDisconnectRetry( )
Get the retry wrapper object that is allows recovery from server disconnects while performing certain database actions, such as executing a query.
Cake\Core\Retry\CommandRetrygetLogger( )
Gets the logger object
getSchemaCollection( )
Gets a Schema\Collection object for this connection.
Cake\Database\Schema\CollectioninTransaction( )
Checks if a transaction is running.
insert( string $table , array $data , array $types = [] )
Executes an INSERT query on the specified table.
$table $data $types optional [] Cake\Database\StatementInterfaceisConnected( )
Returns whether connection to database server was already established.
isQueryLoggingEnabled( )
Check if query logging is enabled.
isSavePointsEnabled( )
Returns whether this connection is using savepoints for nested transactions
log( string $sql )
Logs a Query string using the configured logger object.
$sql logQueries( boolean|null $enable = null )
Enables or disables query logging for this connection.
$enable optional null whether to turn logging on or disable it. Use null to read current value.
Cake\Datasource\ConnectionInterface::logQueries() logger( object|null $instance = null )
Sets the logger object instance. When called with no arguments it returns the currently setup logger instance.
$instance optional null Cake\Datasource\ConnectionInterface::logger() newQuery( )
Create a new Query instance for this connection.
Cake\Database\Queryprepare( string|Cake\Database\Query $sql )
Prepares a SQL statement to be executed.
Cake\Database\Query $sql Cake\Database\StatementInterfacequery( string $sql )
Executes a SQL statement and returns the Statement object as result.
$sql Cake\Database\StatementInterfacequote( mixed $value , string|null $type = null )
Quotes value to be used safely in database query.
$value $type optional null quoteIdentifier( string $identifier )
Quotes a database identifier (a column name, table name, etc..) to be used safely in queries without the risk of using reserved words.
$identifier releaseSavePoint( string $name )
Releases a save point by its name.
$name rollback( boolean|null $toBeginning = null )
Rollback current transaction.
$toBeginning optional null Whether or not the transaction should be rolled back to the beginning of it. Defaults to false if using savepoints, or true if not.
rollbackSavepoint( string $name )
Rollback a save point by its name.
$name run( Cake\Database\Query $query )
Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
Cake\Database\Query $query Cake\Database\StatementInterfaceschemaCollection( Cake\Database\Schema\Collection $collection = null )
Gets or sets a Schema\Collection object for this connection.
Cake\Database\Schema\Collection $collection optional null Cake\Database\Schema\CollectionsetDriver( Cake\Database\Driver|string $driver , array $config = [] )
Sets the driver instance. If a string is passed it will be treated as a class name and will be instantiated.
Cake\Database\Driver|string $driver $config optional [] Cake\Database\Exception\MissingDriverExceptionCake\Database\Exception\MissingExtensionExceptionsetLogger( Cake\Database\Log\QueryLogger $logger )
Sets a logger
$logger setSchemaCollection( Cake\Database\Schema\Collection $collection )
Sets a Schema\Collection object for this connection.
Cake\Database\Schema\Collection $collection supportsDynamicConstraints( )
Returns whether the driver supports adding or dropping constraints to already created tables.
supportsQuoting( )
Checks if the driver supports quoting.
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.
$connection->transactional(function ($connection) {
$connection->newQuery()->delete('users')->execute();
}); $callback Will re-throw any exception raised in $callback after rolling back the transaction.
Cake\Datasource\ConnectionInterface::transactional() update( string $table , array $data , array $conditions = [] , array $types = [] )
Executes an UPDATE statement on the specified table.
$table $data $conditions optional [] $types optional [] Cake\Database\StatementInterfaceuseSavePoints( boolean|null $enable = null )
Returns whether this connection is using savepoints for nested transactions If a boolean is passed as argument it will enable/disable the usage of savepoints only if driver the allows it.
If you are trying to enable this feature, make sure you check the return value of this function to verify it was enabled successfully.
$connection->useSavePoints(true) Returns true if drivers supports save points, false otherwise $connection->useSavePoints(false) Disables usage of savepoints and returns false $connection->useSavePoints() Returns current status
$enable optional null wasNestedTransactionRolledback( )
Returns whether some nested transaction has been already rolled back.
cast( mixed $value , Cake\Database\Type|string $type )
Converts a give value to a suitable database value based on type and return relevant internal statement type
$value Cake\Database\Type|string $type matchTypes( array $columns , array $types )
Matches columns to corresponding types
Both $columns and $types should either be numeric based or string key based at the same time.
$columns $types execute(), getLogger(), getSchemaCollection(), isQueryLoggingEnabled(), newQuery(), prepare(), quote(), supportsDynamicConstraints() |
protected Cake\Database\Driver
Driver object, responsible for creating the real connection and provide specific SQL dialect.
protected Cake\Database\Schema\Collection|null
The schema collection object
protected boolean
Whether a transaction is active in this connection.
false
protected boolean
Whether this connection can and should use savepoints for nested transactions.
false
protected Cake\Database\Exception\NestedTransactionRollbackException|null
NestedTransactionRollbackException object instance, will be stored if the rollback method is called in some nested 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/3.8/class-Cake.Database.Connection.html