$_config
$_config : array
Contains the configuration params for this connection.
Represents a connection with a database server.
$_driver : \Cake\Database\Driver
Driver object, responsible for creating the real connection and provide specific SQL dialect.
$_logger : \Cake\Database\Log\QueryLogger|null
Logger object instance.
$_schemaCollection : \Cake\Database\Schema\Collection|null
The schema collection object
$nestedTransactionRollbackException : \Cake\Database\Exception\NestedTransactionRollbackException|null
NestedTransactionRollbackException object instance, will be stored if the rollback method is called in some nested transaction.
cast(mixed $value, \Cake\Database\Type|string $type) : array
Converts a give value to a suitable database value based on type and return relevant internal statement type
mixed | $value | The value to cast |
\Cake\Database\Type|string | $type | The type name or type instance to use. |
list containing converted value and internal type
matchTypes(array $columns, array $types) : array
Matches columns to corresponding types
Both $columns and $types should either be numeric based or string key based at the same time.
array | $columns | list or associative array of columns and parameters to be bound with types |
array | $types | list or associative array of types |
setDriver(\Cake\Database\Driver|string $driver, array $config = array()) : $this
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 | The driver instance to use. |
array | $config | Config for a new driver. |
When a driver class is missing.
When a driver's PHP extension is missing.
getDisconnectRetry() : \Cake\Core\Retry\CommandRetry
Get the retry wrapper object that is allows recovery from server disconnects while performing certain database actions, such as executing a query.
The retry wrapper
getDriver() : \Cake\Database\Driver
Gets the driver instance.
driver(\Cake\Database\Driver|string|null $driver = null, array $config = array()) : \Cake\Database\Driver
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 | The driver instance to use. |
array | $config | Either config for a new driver or null. |
When a driver class is missing.
When a driver's PHP extension is missing.
connect() : boolean
Connects to the configured database.
if credentials are invalid.
true, if the connection was already established or the attempt was successful.
None found |
None found |
isConnected() : boolean
Returns whether connection to database server was already established.
None found |
prepare(string|\Cake\Database\Query $sql) : \Cake\Database\StatementInterface
Prepares a SQL statement to be executed.
string|\Cake\Database\Query | $sql | The SQL to convert into a prepared statement. |
None found |
execute(string $query, array $params = array(), array $types = array()) : \Cake\Database\StatementInterface
Executes a query using $params for interpolating values and $types as a hint for each those params.
string | $query | SQL to be executed and interpolated with $params |
array | $params | list or associative array of params to be interpolated in $query as values |
array | $types | list or associative array of types to be used for casting values in query |
executed statement
None found |
compileQuery(\Cake\Database\Query $query, \Cake\Database\ValueBinder $generator) : string
Compiles a Query object into a SQL string according to the dialect for this connection's driver
\Cake\Database\Query | $query | The query to be compiled |
\Cake\Database\ValueBinder | $generator | The placeholder generator to use |
None found |
run(\Cake\Database\Query $query) : \Cake\Database\StatementInterface
Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
\Cake\Database\Query | $query | The query to be executed |
executed statement
None found |
query(string $sql) : \Cake\Database\StatementInterface
Executes a SQL statement and returns the Statement object as result.
string | $sql | The SQL query to execute. |
None found |
newQuery() : \Cake\Database\Query
Create a new Query instance for this connection.
None found |
setSchemaCollection(\Cake\Database\Schema\Collection $collection) : $this
Sets a Schema\Collection object for this connection.
\Cake\Database\Schema\Collection | $collection | The schema collection object |
None found |
getSchemaCollection() : \Cake\Database\Schema\Collection
Gets a Schema\Collection object for this connection.
None found |
schemaCollection(\Cake\Database\Schema\Collection|null $collection = null) : \Cake\Database\Schema\Collection
Gets or sets a Schema\Collection object for this connection.
\Cake\Database\Schema\Collection|null | $collection | The schema collection object |
None found |
insert(string $table, array $data, array $types = array()) : \Cake\Database\StatementInterface
Executes an INSERT query on the specified table.
string | $table | the table to insert values in |
array | $data | values to be inserted |
array | $types | list of associative array containing the types to be used for casting |
None found |
update(string $table, array $data, array $conditions = array(), array $types = array()) : \Cake\Database\StatementInterface
Executes an UPDATE statement on the specified table.
string | $table | the table to update rows from |
array | $data | values to be updated |
array | $conditions | conditions to be set for update statement |
array | $types | list of associative array containing the types to be used for casting |
None found |
delete(string $table, array $conditions = array(), array $types = array()) : \Cake\Database\StatementInterface
Executes a DELETE statement on the specified table.
string | $table | the table to delete rows from |
array | $conditions | conditions to be set for delete statement |
array | $types | list of associative array containing the types to be used for casting |
None found |
None found |
commit() : boolean
Commits current transaction.
true on success, false otherwise
None found |
rollback(boolean|null $toBeginning = null) : boolean
Rollback current transaction.
boolean|null | $toBeginning | Whether or not the transaction should be rolled back to the beginning of it. Defaults to false if using savepoints, or true if not. |
None found |
enableSavePoints(boolean $enable) : $this
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
boolean | $enable | Whether or not save points should be used. |
None found |
None found |
isSavePointsEnabled() : boolean
Returns whether this connection is using savepoints for nested transactions
true if enabled, false otherwise
None found |
useSavePoints(boolean|null $enable = null) : boolean
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
boolean|null | $enable | Whether or not save points should be used. |
true if enabled, false otherwise
None found |
createSavePoint(string $name) : void
Creates a new save point for nested transactions.
string | $name | The save point name. |
None found |
releaseSavePoint(string $name) : void
Releases a save point by its name.
string | $name | The save point name. |
None found |
rollbackSavepoint(string $name) : void
Rollback a save point by its name.
string | $name | The save point name. |
None found |
disableForeignKeys() : void
Run driver specific SQL to disable foreign key checks.
None found |
enableForeignKeys() : void
Run driver specific SQL to enable foreign key checks.
None found |
supportsDynamicConstraints() : boolean
Returns whether the driver supports adding or dropping constraints to already created tables.
true if driver supports dynamic constraints
None found |
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.
$connection->transactional(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
callable | $callback |
The return value of the callback.
None found |
disableConstraints(callable $callback) : mixed
Run an operation with constraints disabled.
$connection->disableConstraints(function ($connection) {
$connection->newQuery()->delete('users')->execute();
});
callable | $callback |
The return value of the callback.
None found |
inTransaction() : boolean
Checks if a transaction is running.
True if a transaction is running else false.
None found |
quote(mixed $value, string|null $type = null) : string
Quotes value to be used safely in database query.
mixed | $value | The value to quote. |
string|null | $type | Type to be used for determining kind of quoting to perform |
Quoted value
None found |
supportsQuoting() : boolean
Checks if the driver supports quoting.
None found |
quoteIdentifier(string $identifier) : string
Quotes a database identifier (a column name, table name, etc.
.) to be used safely in queries without the risk of using reserved words.
string | $identifier | The identifier to quote. |
None found |
cacheMetadata(boolean|string $cache) : void
Enables or disables metadata caching for this connection
Changing this setting will not modify existing schema collections objects.
boolean|string | $cache | Either boolean false to disable metadata caching, or
true to use |
None found |
logQueries(boolean|null $enable = null) : boolean
Enables or disables query logging for this connection.
boolean|null | $enable | whether to turn logging on or disable it. Use null to read current value. |
None found |
enableQueryLogging(boolean $value) : $this
Enable/disable query logging
boolean | $value | Enable/disable query logging |
None found |
None found |
isQueryLoggingEnabled() : boolean
Check if query logging is enabled.
None found |
logger(object|null $instance = null) : object
Sets the logger object instance. When called with no arguments it returns the currently setup logger instance.
object|null | $instance | logger object instance |
logger instance
None found |
setLogger(\Cake\Database\Log\QueryLogger $logger) : $this
Sets a logger
\Cake\Database\Log\QueryLogger | $logger | Logger object |
None found |
getLogger() : \Cake\Database\Log\QueryLogger
Gets the logger object
logger instance
None found |
log(string $sql) : void
Logs a Query string using the configured logger object.
string | $sql | string to be logged |
None found |
__debugInfo() : array
Returns an array that can be used to describe the internal state of this object.
None found |
wasNestedTransactionRolledback() : boolean
Returns whether some nested transaction has been already rolled back.
None found |
_newLogger(\Cake\Database\StatementInterface $statement) : \Cake\Database\Log\LoggingStatement
Returns a new statement object that will log the activity for the passed original statement instance.
\Cake\Database\StatementInterface | $statement | the instance to be decorated |
None found |