PHP 클래스 Cake\Database\Connection

상속: implements Cake\Datasource\ConnectionInterface, use trait Cake\Database\TypeConverterTrait
파일 보기 프로젝트 열기: cakephp/cakephp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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