PHP Class Cake\Database\Connection

Inheritance: implements Cake\Datasource\ConnectionInterface, use trait Cake\Database\TypeConverterTrait
Afficher le fichier Open project: cakephp/cakephp Class Usage Examples

Protected Properties

Свойство Type Description
$_config array Contains the configuration params for this connection.
$_driver Cake\Database\Driver Driver object, responsible for creating the real connection and provide specific SQL dialect.
$_logQueries boolean Whether to log queries generated during this connection.
$_logger Cake\Database\Log\QueryLogger Logger object instance.
$_schemaCollection Cake\Database\Schema\Collection The schema collection object
$_transactionLevel integer Contains how many nested transactions have been started.
$_transactionStarted boolean Whether a transaction is active in this connection.
$_useSavePoints boolean Whether this connection can and should use savepoints for nested transactions.

Méthodes publiques

Méthode Description
__construct ( array $config ) Constructor.
__debugInfo ( ) : array Returns an array that can be used to describe the internal state of this object.
__destruct ( ) Destructor
begin ( ) : void Starts a new transaction.
cacheMetadata ( boolean | string $cache ) : void Enables or disables metadata caching for this connection
commit ( ) : boolean Commits current transaction.
compileQuery ( Query $query, ValueBinder $generator ) : string Compiles a Query object into a SQL string according to the dialect for this connection's driver
config ( ) {@inheritDoc}
configName ( ) {@inheritDoc}
connect ( ) : boolean Connects to the configured database.
createSavePoint ( string $name ) : void Creates a new save point for nested transactions.
delete ( string $table, array $conditions = [], array $types = [] ) : Cake\Database\StatementInterface Executes a DELETE statement on the specified table.
disableConstraints ( callable $callback ) {@inheritDoc}
disableForeignKeys ( ) : void Run driver specific SQL to disable foreign key checks.
disconnect ( ) : void Disconnects from database server.
driver ( Cake\Database\Driver | string | null $driver = null, array $config = [] ) : Cake\Database\Driver Sets the driver instance. If a string is passed it will be treated as a class name and will be instantiated.
enableForeignKeys ( ) : void Run driver specific SQL to enable foreign key checks.
execute ( string $query, array $params = [], array $types = [] ) : Cake\Database\StatementInterface Executes a query using $params for interpolating values and $types as a hint for each those params.
inTransaction ( ) : boolean Checks if a transaction is running.
insert ( string $table, array $data, array $types = [] ) : Cake\Database\StatementInterface Executes an INSERT query on the specified table.
isConnected ( ) : boolean Returns whether connection to database server was already established.
log ( string $sql ) : void Logs a Query string using the configured logger object.
logQueries ( $enable = null ) {@inheritDoc}
logger ( $instance = null ) {@inheritDoc}
newQuery ( ) : Query Create a new Query instance for this connection.
prepare ( string | Query $sql ) : Cake\Database\StatementInterface Prepares a SQL statement to be executed.
query ( string $sql ) : Cake\Database\StatementInterface Executes a SQL statement and returns the Statement object as result.
quote ( mixed $value, string | null $type = null ) : string Quotes value to be used safely in database query.
quoteIdentifier ( string $identifier ) : string Quotes a database identifier (a column name, table name, etc.
releaseSavePoint ( string $name ) : void Releases a save point by its name.
rollback ( ) : boolean Rollback current transaction.
rollbackSavepoint ( string $name ) : void Rollback a save point by its name.
run ( Query $query ) : Cake\Database\StatementInterface Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
schemaCollection ( Cake\Database\Schema\Collection $collection = null ) : Cake\Database\Schema\Collection Gets or sets a Schema\Collection object for this connection.
supportsDynamicConstraints ( ) : boolean Returns whether the driver supports adding or dropping constraints to already created tables.
supportsQuoting ( ) : boolean Checks if the driver supports quoting.
transactional ( callable $callback ) {@inheritDoc}
update ( string $table, array $data, array $conditions = [], array $types = [] ) : Cake\Database\StatementInterface Executes an UPDATE statement on the specified table.
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.

Méthodes protégées

Méthode Description
_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.

Method Details

__construct() public méthode

Constructor.
public __construct ( array $config )
$config array configuration for connecting to database

__debugInfo() public méthode

Returns an array that can be used to describe the internal state of this object.
public __debugInfo ( ) : array
Résultat array

__destruct() public méthode

Disconnects the driver to release the connection.
public __destruct ( )

_newLogger() protected méthode

Returns a new statement object that will log the activity for the passed original statement instance.
protected _newLogger ( Cake\Database\StatementInterface $statement ) : Cake\Database\Log\LoggingStatement
$statement Cake\Database\StatementInterface the instance to be decorated
Résultat Cake\Database\Log\LoggingStatement

begin() public méthode

Starts a new transaction.
public begin ( ) : void
Résultat void

cacheMetadata() public méthode

Changing this setting will not modify existing schema collections objects.
public cacheMetadata ( boolean | string $cache ) : void
$cache boolean | string Either boolean false to disable meta dataing caching, or true to use `_cake_model_` or the name of the cache config to use.
Résultat void

commit() public méthode

Commits current transaction.
public commit ( ) : boolean
Résultat boolean true on success, false otherwise

compileQuery() public méthode

Compiles a Query object into a SQL string according to the dialect for this connection's driver
public compileQuery ( Query $query, ValueBinder $generator ) : string
$query Query The query to be compiled
$generator ValueBinder The placeholder generator to use
Résultat string

config() public méthode

{@inheritDoc}
public config ( )

configName() public méthode

{@inheritDoc}
public configName ( )

connect() public méthode

Connects to the configured database.
public connect ( ) : boolean
Résultat boolean true on success or false if already connected.

createSavePoint() public méthode

Creates a new save point for nested transactions.
public createSavePoint ( string $name ) : void
$name string The save point name.
Résultat void

delete() public méthode

Executes a DELETE statement on the specified table.
public delete ( string $table, array $conditions = [], array $types = [] ) : Cake\Database\StatementInterface
$table string the table to delete rows from
$conditions array conditions to be set for delete statement
$types array list of associative array containing the types to be used for casting
Résultat Cake\Database\StatementInterface

disableConstraints() public méthode

### Example: $connection->disableConstraints(function ($connection) { $connection->newQuery()->delete('users')->execute(); });
public disableConstraints ( callable $callback )
$callback callable

disableForeignKeys() public méthode

Run driver specific SQL to disable foreign key checks.
public disableForeignKeys ( ) : void
Résultat void

disconnect() public méthode

Disconnects from database server.
public disconnect ( ) : void
Résultat void

driver() public méthode

If no params are passed it will return the current driver instance.
public driver ( Cake\Database\Driver | string | null $driver = null, array $config = [] ) : Cake\Database\Driver
$driver Cake\Database\Driver | string | null The driver instance to use.
$config array Either config for a new driver or null.
Résultat Cake\Database\Driver

enableForeignKeys() public méthode

Run driver specific SQL to enable foreign key checks.
public enableForeignKeys ( ) : void
Résultat void

execute() public méthode

Executes a query using $params for interpolating values and $types as a hint for each those params.
public execute ( string $query, array $params = [], array $types = [] ) : Cake\Database\StatementInterface
$query string SQL to be executed and interpolated with $params
$params array list or associative array of params to be interpolated in $query as values
$types array list or associative array of types to be used for casting values in query
Résultat Cake\Database\StatementInterface executed statement

inTransaction() public méthode

Checks if a transaction is running.
public inTransaction ( ) : boolean
Résultat boolean True if a transaction is running else false.

insert() public méthode

Executes an INSERT query on the specified table.
public insert ( string $table, array $data, array $types = [] ) : Cake\Database\StatementInterface
$table string the table to insert values in
$data array values to be inserted
$types array list of associative array containing the types to be used for casting
Résultat Cake\Database\StatementInterface

isConnected() public méthode

Returns whether connection to database server was already established.
public isConnected ( ) : boolean
Résultat boolean

log() public méthode

Logs a Query string using the configured logger object.
public log ( string $sql ) : void
$sql string string to be logged
Résultat void

logQueries() public méthode

{@inheritDoc}
public logQueries ( $enable = null )

logger() public méthode

{@inheritDoc}
public logger ( $instance = null )

newQuery() public méthode

Create a new Query instance for this connection.
public newQuery ( ) : Query
Résultat Query

prepare() public méthode

Prepares a SQL statement to be executed.
public prepare ( string | Query $sql ) : Cake\Database\StatementInterface
$sql string | Query The SQL to convert into a prepared statement.
Résultat Cake\Database\StatementInterface

query() public méthode

Executes a SQL statement and returns the Statement object as result.
public query ( string $sql ) : Cake\Database\StatementInterface
$sql string The SQL query to execute.
Résultat Cake\Database\StatementInterface

quote() public méthode

Quotes value to be used safely in database query.
public quote ( mixed $value, string | null $type = null ) : string
$value mixed The value to quote.
$type string | null Type to be used for determining kind of quoting to perform
Résultat string Quoted value

quoteIdentifier() public méthode

.) to be used safely in queries without the risk of using reserved words.
public quoteIdentifier ( string $identifier ) : string
$identifier string The identifier to quote.
Résultat string

releaseSavePoint() public méthode

Releases a save point by its name.
public releaseSavePoint ( string $name ) : void
$name string The save point name.
Résultat void

rollback() public méthode

Rollback current transaction.
public rollback ( ) : boolean
Résultat boolean

rollbackSavepoint() public méthode

Rollback a save point by its name.
public rollbackSavepoint ( string $name ) : void
$name string The save point name.
Résultat void

run() public méthode

Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object.
public run ( Query $query ) : Cake\Database\StatementInterface
$query Query The query to be executed
Résultat Cake\Database\StatementInterface executed statement

schemaCollection() public méthode

Gets or sets a Schema\Collection object for this connection.
public schemaCollection ( Cake\Database\Schema\Collection $collection = null ) : Cake\Database\Schema\Collection
$collection Cake\Database\Schema\Collection The schema collection object
Résultat Cake\Database\Schema\Collection

supportsDynamicConstraints() public méthode

Returns whether the driver supports adding or dropping constraints to already created tables.
public supportsDynamicConstraints ( ) : boolean
Résultat boolean true if driver supports dynamic constraints

supportsQuoting() public méthode

Checks if the driver supports quoting.
public supportsQuoting ( ) : boolean
Résultat boolean

transactional() public méthode

### Example: $connection->transactional(function ($connection) { $connection->newQuery()->delete('users')->execute(); });
public transactional ( callable $callback )
$callback callable

update() public méthode

Executes an UPDATE statement on the specified table.
public update ( string $table, array $data, array $conditions = [], array $types = [] ) : Cake\Database\StatementInterface
$table string the table to update rows from
$data array values to be updated
$conditions array conditions to be set for update statement
$types array list of associative array containing the types to be used for casting
Résultat Cake\Database\StatementInterface

useSavePoints() public méthode

If you are trying to enable this feature, make sure you check the return value of this function to verify it was enabled successfully. ### Example: $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
public useSavePoints ( boolean | null $enable = null ) : boolean
$enable boolean | null Whether or not save points should be used.
Résultat boolean true if enabled, false otherwise

Property Details

$_config protected_oe property

Contains the configuration params for this connection.
protected array $_config
Résultat array

$_driver protected_oe property

Driver object, responsible for creating the real connection and provide specific SQL dialect.
protected Driver,Cake\Database $_driver
Résultat Cake\Database\Driver

$_logQueries protected_oe property

Whether to log queries generated during this connection.
protected bool $_logQueries
Résultat boolean

$_logger protected_oe property

Logger object instance.
protected QueryLogger,Cake\Database\Log $_logger
Résultat Cake\Database\Log\QueryLogger

$_schemaCollection protected_oe property

The schema collection object
protected Collection,Cake\Database\Schema $_schemaCollection
Résultat Cake\Database\Schema\Collection

$_transactionLevel protected_oe property

Contains how many nested transactions have been started.
protected int $_transactionLevel
Résultat integer

$_transactionStarted protected_oe property

Whether a transaction is active in this connection.
protected bool $_transactionStarted
Résultat boolean

$_useSavePoints protected_oe property

Whether this connection can and should use savepoints for nested transactions.
protected bool $_useSavePoints
Résultat boolean