Represents a connection with a database server.
__construct( array $config )
Constructor.
$config __debugInfo( )
Returns an array that can be used to describe the internal state of this object.
array_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 Cake\Database\Log\LoggingStatementcacheMetadata( boolean|string $cache )
Enables or disables metadata caching for this connection
Changing this setting will not modify existing schema collections objects.
$cache _cake_model_ or the name of the cache config to use.commit( )
Commits current transaction.
booleancompileQuery( 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 stringconfig( )
Get the configuration data used to create the connection.
arrayCake\Datasource\ConnectionInterface::config() configName( )
Get the configuration name for this connection.
stringCake\Datasource\ConnectionInterface::configName() connect( )
Connects to the configured database.
booleanCake\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 mixedExceptionCake\Datasource\ConnectionInterface::disableConstraints() disableForeignKeys( )
Run driver specific SQL to disable foreign key checks.
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.
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\StatementInterfaceinTransaction( )
Checks if a transaction is running.
booleaninsert( 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.
booleanlog( string $sql )
Logs a Query string using the configured logger object.
$sql logQueries( boolean $enable null )
Enables or disables query logging for this connection.
$enable optional null booleanCake\Datasource\ConnectionInterface::logQueries() logger( object $instance null )
Sets the logger object instance. When called with no arguments it returns the currently setup logger instance.
$instance optional null objectCake\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 $type null )
Quotes value to be used safely in database query.
$value $type optional null stringquoteIdentifier( 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 stringreleaseSavePoint( string $name )
Releases a save point by its name.
$name 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\CollectionsupportsDynamicConstraints( )
Returns whether the driver supports adding or dropping constraints to already created tables.
booleansupportsQuoting( )
Checks if the driver supports quoting.
booleantransactional( 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 mixedExceptionCake\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 booleancast( 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 arraymatchTypes( 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 array
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Database.Connection.html