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\LoggingStatement
cacheMetadata( 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.
boolean
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
string
config( )
Get the configuration data used to create the connection.
array
Cake\Datasource\ConnectionInterface::config()
configName( )
Get the configuration name for this connection.
string
Cake\Datasource\ConnectionInterface::configName()
connect( )
Connects to the configured database.
boolean
Cake\Database\Exception\MissingConnectionException
createSavePoint( 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\StatementInterface
disableConstraints( callable $callback )
Run an operation with constraints disabled.
$connection->disableConstraints(function ($connection) { $connection->newQuery()->delete('users')->execute(); });
$callback
mixed
Exception
Cake\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\Driver
Cake\Database\Exception\MissingDriverException
Cake\Database\Exception\MissingExtensionException
enableForeignKeys( )
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\StatementInterface
inTransaction( )
Checks if a transaction is running.
boolean
insert( string $table , array $data , array $types [] )
Executes an INSERT query on the specified table.
$table
$data
$types
optional [] Cake\Database\StatementInterface
isConnected( )
Returns whether connection to database server was already established.
boolean
log( 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 boolean
Cake\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 object
Cake\Datasource\ConnectionInterface::logger()
newQuery( )
Create a new Query instance for this connection.
Cake\Database\Query
prepare( string|Cake\Database\Query $sql )
Prepares a SQL statement to be executed.
Cake\Database\Query
$sql
Cake\Database\StatementInterface
query( string $sql )
Executes a SQL statement and returns the Statement object as result.
$sql
Cake\Database\StatementInterface
quote( mixed $value , string $type null )
Quotes value to be used safely in database query.
$value
$type
optional null string
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
string
releaseSavePoint( 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\StatementInterface
schemaCollection( 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\Collection
supportsDynamicConstraints( )
Returns whether the driver supports adding or dropping constraints to already created tables.
boolean
supportsQuoting( )
Checks if the driver supports quoting.
boolean
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
mixed
Exception
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\StatementInterface
useSavePoints( 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 boolean
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
array
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
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