PHP Класс Cake\Database\Connection

Наследование: implements Cake\Datasource\ConnectionInterface, use trait Cake\Database\TypeConverterTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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.

Описание методов

__construct() публичный метод

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

__debugInfo() публичный метод

Returns an array that can be used to describe the internal state of this object.
public __debugInfo ( ) : array
Результат array

__destruct() публичный метод

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

_newLogger() защищенный метод

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
Результат Cake\Database\Log\LoggingStatement

begin() публичный метод

Starts a new transaction.
public begin ( ) : void
Результат void

cacheMetadata() публичный метод

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.
Результат void

commit() публичный метод

Commits current transaction.
public commit ( ) : boolean
Результат boolean true on success, false otherwise

compileQuery() публичный метод

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
Результат string

config() публичный метод

{@inheritDoc}
public config ( )

configName() публичный метод

{@inheritDoc}
public configName ( )

connect() публичный метод

Connects to the configured database.
public connect ( ) : boolean
Результат boolean true on success or false if already connected.

createSavePoint() публичный метод

Creates a new save point for nested transactions.
public createSavePoint ( string $name ) : void
$name string The save point name.
Результат void

delete() публичный метод

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
Результат Cake\Database\StatementInterface

disableConstraints() публичный метод

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

disableForeignKeys() публичный метод

Run driver specific SQL to disable foreign key checks.
public disableForeignKeys ( ) : void
Результат void

disconnect() публичный метод

Disconnects from database server.
public disconnect ( ) : void
Результат void

driver() публичный метод

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.
Результат Cake\Database\Driver

enableForeignKeys() публичный метод

Run driver specific SQL to enable foreign key checks.
public enableForeignKeys ( ) : void
Результат void

execute() публичный метод

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
Результат Cake\Database\StatementInterface executed statement

inTransaction() публичный метод

Checks if a transaction is running.
public inTransaction ( ) : boolean
Результат boolean True if a transaction is running else false.

insert() публичный метод

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
Результат Cake\Database\StatementInterface

isConnected() публичный метод

Returns whether connection to database server was already established.
public isConnected ( ) : boolean
Результат boolean

log() публичный метод

Logs a Query string using the configured logger object.
public log ( string $sql ) : void
$sql string string to be logged
Результат void

logQueries() публичный метод

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

logger() публичный метод

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

newQuery() публичный метод

Create a new Query instance for this connection.
public newQuery ( ) : Query
Результат Query

prepare() публичный метод

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.
Результат Cake\Database\StatementInterface

query() публичный метод

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.
Результат Cake\Database\StatementInterface

quote() публичный метод

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
Результат string Quoted value

quoteIdentifier() публичный метод

.) to be used safely in queries without the risk of using reserved words.
public quoteIdentifier ( string $identifier ) : string
$identifier string The identifier to quote.
Результат string

releaseSavePoint() публичный метод

Releases a save point by its name.
public releaseSavePoint ( string $name ) : void
$name string The save point name.
Результат void

rollback() публичный метод

Rollback current transaction.
public rollback ( ) : boolean
Результат boolean

rollbackSavepoint() публичный метод

Rollback a save point by its name.
public rollbackSavepoint ( string $name ) : void
$name string The save point name.
Результат void

run() публичный метод

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
Результат Cake\Database\StatementInterface executed statement

schemaCollection() публичный метод

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
Результат Cake\Database\Schema\Collection

supportsDynamicConstraints() публичный метод

Returns whether the driver supports adding or dropping constraints to already created tables.
public supportsDynamicConstraints ( ) : boolean
Результат boolean true if driver supports dynamic constraints

supportsQuoting() публичный метод

Checks if the driver supports quoting.
public supportsQuoting ( ) : boolean
Результат boolean

transactional() публичный метод

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

update() публичный метод

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
Результат Cake\Database\StatementInterface

useSavePoints() публичный метод

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.
Результат boolean true if enabled, false otherwise

Описание свойств

$_config защищенное свойство

Contains the configuration params for this connection.
protected array $_config
Результат array

$_driver защищенное свойство

Driver object, responsible for creating the real connection and provide specific SQL dialect.
protected Driver,Cake\Database $_driver
Результат Cake\Database\Driver

$_logQueries защищенное свойство

Whether to log queries generated during this connection.
protected bool $_logQueries
Результат boolean

$_logger защищенное свойство

Logger object instance.
protected QueryLogger,Cake\Database\Log $_logger
Результат Cake\Database\Log\QueryLogger

$_schemaCollection защищенное свойство

The schema collection object
protected Collection,Cake\Database\Schema $_schemaCollection
Результат Cake\Database\Schema\Collection

$_transactionLevel защищенное свойство

Contains how many nested transactions have been started.
protected int $_transactionLevel
Результат integer

$_transactionStarted защищенное свойство

Whether a transaction is active in this connection.
protected bool $_transactionStarted
Результат boolean

$_useSavePoints защищенное свойство

Whether this connection can and should use savepoints for nested transactions.
protected bool $_useSavePoints
Результат boolean