PHP Interface Doctrine\DBAL\Connection

Afficher le fichier Open project: doctrine/dbal Interface Usage Examples

Protected Properties

Свойство Type Description
$_config Doctrine\DBAL\Configuration
$_conn Doctrine\DBAL\Driver\Connection The wrapped driver connection.
$_driver Doctrine\DBAL\Driver The used DBAL driver.
$_eventManager Doctrine\Common\EventManager
$_expr Doctrine\DBAL\Query\Expression\ExpressionBuilder
$_schemaManager Doctrine\DBAL\Schema\AbstractSchemaManager The schema manager.
$defaultFetchMode integer

Méthodes publiques

Méthode Description
__construct ( array $params, Doctrine\DBAL\Driver $driver, Doctrine\DBAL\Configuration $config = null, Doctrine\Common\EventManager $eventManager = null ) Initializes a new instance of the Connection class.
beginTransaction ( ) : void Starts a transaction by suspending auto-commit mode.
close ( ) : void Closes the connection.
commit ( ) : void Commits the current transaction.
connect ( ) : boolean Establishes the connection with the database.
convertToDatabaseValue ( mixed $value, string $type ) : mixed Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type.
convertToPHPValue ( mixed $value, string $type ) : mixed Converts a given value to its PHP representation according to the conversion rules of a specific DBAL mapping type.
createQueryBuilder ( ) : Doctrine\DBAL\Query\QueryBuilder Creates a new instance of a SQL query builder.
createSavepoint ( string $savepoint ) : void Creates a new savepoint.
delete ( string $tableExpression, array $identifier, array $types = [] ) : integer Executes an SQL DELETE statement on a table.
errorCode ( ) : integer Fetches the SQLSTATE associated with the last database operation.
errorInfo ( ) : array Fetches extended error information associated with the last database operation.
exec ( string $statement ) : integer Executes an SQL statement and return the number of affected rows.
executeCacheQuery ( string $query, array $params, array $types, Doctrine\DBAL\Cache\QueryCacheProfile $qcp ) : Doctrine\DBAL\Driver\ResultStatement Executes a caching query.
executeQuery ( string $query, array $params = [], array $types = [], Doctrine\DBAL\Cache\QueryCacheProfile $qcp = null ) : Doctrine\DBAL\Driver\Statement Executes an, optionally parametrized, SQL query.
executeUpdate ( string $query, array $params = [], array $types = [] ) : integer Executes an SQL INSERT/UPDATE/DELETE query with the given parameters and returns the number of affected rows.
fetchAll ( string $sql, array $params = [], array $types = [] ) : array Prepares and executes an SQL query and returns the result as an associative array.
fetchArray ( string $statement, array $params = [], array $types = [] ) : array | boolean Prepares and executes an SQL query and returns the first row of the result as a numerically indexed array.
fetchAssoc ( string $statement, array $params = [], array $types = [] ) : array | boolean Prepares and executes an SQL query and returns the first row of the result as an associative array.
fetchColumn ( string $statement, array $params = [], integer $column, array $types = [] ) : mixed | boolean Prepares and executes an SQL query and returns the value of a single column of the first row of the result.
getConfiguration ( ) : Doctrine\DBAL\Configuration Gets the Configuration used by the Connection.
getDatabase ( ) : string Gets the name of the database this Connection is connected to.
getDatabasePlatform ( ) : Doctrine\DBAL\Platforms\AbstractPlatform Gets the DatabasePlatform for the connection.
getDriver ( ) : Doctrine\DBAL\Driver Gets the DBAL driver instance.
getEventManager ( ) : Doctrine\Common\EventManager Gets the EventManager used by the Connection.
getExpressionBuilder ( ) : Doctrine\DBAL\Query\Expression\ExpressionBuilder Gets the ExpressionBuilder for the connection.
getHost ( ) : string | null Gets the hostname of the currently connected database.
getNestTransactionsWithSavepoints ( ) : boolean Gets if nested transactions should use savepoints.
getParams ( ) : array Gets the parameters used during instantiation.
getPassword ( ) : string | null Gets the password used by this connection.
getPort ( ) : mixed Gets the port of the currently connected database.
getSchemaManager ( ) : Doctrine\DBAL\Schema\AbstractSchemaManager Gets the SchemaManager that can be used to inspect or change the database schema through the connection.
getTransactionIsolation ( ) : integer Gets the currently active transaction isolation level.
getTransactionNestingLevel ( ) : integer Returns the current transaction nesting level.
getUsername ( ) : string | null Gets the username used by this connection.
getWrappedConnection ( ) : Doctrine\DBAL\Driver\Connection Gets the wrapped driver connection.
insert ( string $tableExpression, array $data, array $types = [] ) : integer Inserts a table row with specified data.
isAutoCommit ( ) : boolean Returns the current auto-commit mode for this connection.
isConnected ( ) : boolean Whether an actual connection to the database is established.
isRollbackOnly ( ) : boolean Checks whether the current transaction is marked for rollback only.
isTransactionActive ( ) : boolean Checks whether a transaction is currently active.
lastInsertId ( string | null $seqName = null ) : string Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver.
ping ( ) : boolean Ping the server
prepare ( string $statement ) : Statement Prepares an SQL statement.
project ( string $query, array $params, Closur\Closure $function ) : array Executes an, optionally parametrized, SQL query and returns the result, applying a given projection/transformation function on each row of the result.
query ( ) : Doctrine\DBAL\Driver\Statement Executes an SQL statement, returning a result set as a Statement object.
quote ( mixed $input, string | null $type = null ) : string Quotes a given input parameter.
quoteIdentifier ( string $str ) : string Quotes a string so it can be safely used as a table or column name, even if it is a reserved name.
releaseSavepoint ( string $savepoint ) : void Releases the given savepoint.
resolveParams ( array $params, array $types ) : array Resolves the parameters to a format which can be displayed.
rollBack ( ) Cancels any database changes done during the current transaction.
rollbackSavepoint ( string $savepoint ) : void Rolls back to the given savepoint.
setAutoCommit ( boolean $autoCommit ) Sets auto-commit mode for this connection.
setFetchMode ( integer $fetchMode ) : void Sets the fetch mode.
setNestTransactionsWithSavepoints ( boolean $nestTransactionsWithSavepoints ) : void Sets if nested transactions should use savepoints.
setRollbackOnly ( ) : void Marks the current transaction so that the only possible outcome for the transaction to be rolled back.
setTransactionIsolation ( integer $level ) : integer Sets the transaction isolation level.
transactional ( Closur\Closure $func ) : mixed Executes a function in a transaction.
update ( string $tableExpression, array $data, array $identifier, array $types = [] ) : integer Executes an SQL UPDATE statement on a table.

Méthodes protégées

Méthode Description
_getNestedTransactionSavePointName ( ) : mixed Returns the savepoint name to use for nested transactions are false if they are not supported "savepointFormat" parameter is not set

Private Methods

Méthode Description
_bindTypedValues ( Doctrine\DBAL\Driver\Statement $stmt, array $params, array $types ) : void Binds a set of parameters, some or all of which are typed with a PDO binding type or DBAL mapping type, to a given statement.
commitAll ( ) Commits all current nesting transactions.
detectDatabasePlatform ( ) Detects and sets the database platform.
extractTypeValues ( array $data, array $types ) : array Extract ordered type list from two associate key lists of data and types.
getBindingInfo ( mixed $value, mixed $type ) : array Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type.
getDatabasePlatformVersion ( ) : string | null Returns the version of the related platform if applicable.

Method Details

__construct() public méthode

Initializes a new instance of the Connection class.
public __construct ( array $params, Doctrine\DBAL\Driver $driver, Doctrine\DBAL\Configuration $config = null, Doctrine\Common\EventManager $eventManager = null )
$params array The connection parameters.
$driver Doctrine\DBAL\Driver The driver to use.
$config Doctrine\DBAL\Configuration The configuration, optional.
$eventManager Doctrine\Common\EventManager The event manager, optional.

_getNestedTransactionSavePointName() protected méthode

Returns the savepoint name to use for nested transactions are false if they are not supported "savepointFormat" parameter is not set
protected _getNestedTransactionSavePointName ( ) : mixed
Résultat mixed A string with the savepoint name or false.

beginTransaction() public méthode

Starts a transaction by suspending auto-commit mode.
public beginTransaction ( ) : void
Résultat void

close() public méthode

Closes the connection.
public close ( ) : void
Résultat void

commit() public méthode

Commits the current transaction.
public commit ( ) : void
Résultat void

connect() public méthode

Establishes the connection with the database.
public connect ( ) : boolean
Résultat boolean TRUE if the connection was successfully established, FALSE if the connection is already open.

convertToDatabaseValue() public méthode

Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type.
public convertToDatabaseValue ( mixed $value, string $type ) : mixed
$value mixed The value to convert.
$type string The name of the DBAL mapping type.
Résultat mixed The converted value.

convertToPHPValue() public méthode

Converts a given value to its PHP representation according to the conversion rules of a specific DBAL mapping type.
public convertToPHPValue ( mixed $value, string $type ) : mixed
$value mixed The value to convert.
$type string The name of the DBAL mapping type.
Résultat mixed The converted type.

createQueryBuilder() public méthode

Creates a new instance of a SQL query builder.
public createQueryBuilder ( ) : Doctrine\DBAL\Query\QueryBuilder
Résultat Doctrine\DBAL\Query\QueryBuilder

createSavepoint() public méthode

Creates a new savepoint.
public createSavepoint ( string $savepoint ) : void
$savepoint string The name of the savepoint to create.
Résultat void

delete() public méthode

Table expression and columns are not escaped and are not safe for user-input.
public delete ( string $tableExpression, array $identifier, array $types = [] ) : integer
$tableExpression string The expression of the table on which to delete.
$identifier array The deletion criteria. An associative array containing column-value pairs.
$types array The types of identifiers.
Résultat integer The number of affected rows.

errorCode() public méthode

Fetches the SQLSTATE associated with the last database operation.
public errorCode ( ) : integer
Résultat integer The last error code.

errorInfo() public méthode

Fetches extended error information associated with the last database operation.
public errorInfo ( ) : array
Résultat array The last error information.

exec() public méthode

Executes an SQL statement and return the number of affected rows.
public exec ( string $statement ) : integer
$statement string
Résultat integer The number of affected rows.

executeCacheQuery() public méthode

Executes a caching query.
public executeCacheQuery ( string $query, array $params, array $types, Doctrine\DBAL\Cache\QueryCacheProfile $qcp ) : Doctrine\DBAL\Driver\ResultStatement
$query string The SQL query to execute.
$params array The parameters to bind to the query, if any.
$types array The types the previous parameters are in.
$qcp Doctrine\DBAL\Cache\QueryCacheProfile The query cache profile.
Résultat Doctrine\DBAL\Driver\ResultStatement

executeQuery() public méthode

If the query is parametrized, a prepared statement is used. If an SQLLogger is configured, the execution is logged.
public executeQuery ( string $query, array $params = [], array $types = [], Doctrine\DBAL\Cache\QueryCacheProfile $qcp = null ) : Doctrine\DBAL\Driver\Statement
$query string The SQL query to execute.
$params array The parameters to bind to the query, if any.
$types array The types the previous parameters are in.
$qcp Doctrine\DBAL\Cache\QueryCacheProfile The query cache profile, optional.
Résultat Doctrine\DBAL\Driver\Statement The executed statement.

executeUpdate() public méthode

This method supports PDO binding types as well as DBAL mapping types.
public executeUpdate ( string $query, array $params = [], array $types = [] ) : integer
$query string The SQL query.
$params array The query parameters.
$types array The parameter types.
Résultat integer The number of affected rows.

fetchAll() public méthode

Prepares and executes an SQL query and returns the result as an associative array.
public fetchAll ( string $sql, array $params = [], array $types = [] ) : array
$sql string The SQL query.
$params array The query parameters.
$types array The query parameter types.
Résultat array

fetchArray() public méthode

Prepares and executes an SQL query and returns the first row of the result as a numerically indexed array.
public fetchArray ( string $statement, array $params = [], array $types = [] ) : array | boolean
$statement string The SQL query to be executed.
$params array The prepared statement params.
$types array The query parameter types.
Résultat array | boolean False is returned if no rows are found.

fetchAssoc() public méthode

Prepares and executes an SQL query and returns the first row of the result as an associative array.
public fetchAssoc ( string $statement, array $params = [], array $types = [] ) : array | boolean
$statement string The SQL query.
$params array The query parameters.
$types array The query parameter types.
Résultat array | boolean False is returned if no rows are found.

fetchColumn() public méthode

Prepares and executes an SQL query and returns the value of a single column of the first row of the result.
public fetchColumn ( string $statement, array $params = [], integer $column, array $types = [] ) : mixed | boolean
$statement string The SQL query to be executed.
$params array The prepared statement params.
$column integer The 0-indexed column number to retrieve.
$types array The query parameter types.
Résultat mixed | boolean False is returned if no rows are found.

getConfiguration() public méthode

Gets the Configuration used by the Connection.
public getConfiguration ( ) : Doctrine\DBAL\Configuration
Résultat Doctrine\DBAL\Configuration

getDatabase() public méthode

Gets the name of the database this Connection is connected to.
public getDatabase ( ) : string
Résultat string

getDatabasePlatform() public méthode

Gets the DatabasePlatform for the connection.
public getDatabasePlatform ( ) : Doctrine\DBAL\Platforms\AbstractPlatform
Résultat Doctrine\DBAL\Platforms\AbstractPlatform

getDriver() public méthode

Gets the DBAL driver instance.
public getDriver ( ) : Doctrine\DBAL\Driver
Résultat Doctrine\DBAL\Driver

getEventManager() public méthode

Gets the EventManager used by the Connection.
public getEventManager ( ) : Doctrine\Common\EventManager
Résultat Doctrine\Common\EventManager

getExpressionBuilder() public méthode

Gets the ExpressionBuilder for the connection.
public getExpressionBuilder ( ) : Doctrine\DBAL\Query\Expression\ExpressionBuilder
Résultat Doctrine\DBAL\Query\Expression\ExpressionBuilder

getHost() public méthode

Gets the hostname of the currently connected database.
public getHost ( ) : string | null
Résultat string | null

getNestTransactionsWithSavepoints() public méthode

Gets if nested transactions should use savepoints.

getParams() public méthode

Gets the parameters used during instantiation.
public getParams ( ) : array
Résultat array

getPassword() public méthode

Gets the password used by this connection.
public getPassword ( ) : string | null
Résultat string | null

getPort() public méthode

Gets the port of the currently connected database.
public getPort ( ) : mixed
Résultat mixed

getSchemaManager() public méthode

Gets the SchemaManager that can be used to inspect or change the database schema through the connection.
public getSchemaManager ( ) : Doctrine\DBAL\Schema\AbstractSchemaManager
Résultat Doctrine\DBAL\Schema\AbstractSchemaManager

getTransactionIsolation() public méthode

Gets the currently active transaction isolation level.
public getTransactionIsolation ( ) : integer
Résultat integer The current transaction isolation level.

getTransactionNestingLevel() public méthode

Returns the current transaction nesting level.
public getTransactionNestingLevel ( ) : integer
Résultat integer The nesting level. A value of 0 means there's no active transaction.

getUsername() public méthode

Gets the username used by this connection.
public getUsername ( ) : string | null
Résultat string | null

getWrappedConnection() public méthode

Gets the wrapped driver connection.
public getWrappedConnection ( ) : Doctrine\DBAL\Driver\Connection
Résultat Doctrine\DBAL\Driver\Connection

insert() public méthode

Table expression and columns are not escaped and are not safe for user-input.
public insert ( string $tableExpression, array $data, array $types = [] ) : integer
$tableExpression string The expression of the table to insert data into, quoted or unquoted.
$data array An associative array containing column-value pairs.
$types array Types of the inserted data.
Résultat integer The number of affected rows.

isAutoCommit() public méthode

Returns the current auto-commit mode for this connection.
See also: setAutoCommit
public isAutoCommit ( ) : boolean
Résultat boolean True if auto-commit mode is currently enabled for this connection, false otherwise.

isConnected() public méthode

Whether an actual connection to the database is established.
public isConnected ( ) : boolean
Résultat boolean

isRollbackOnly() public méthode

Checks whether the current transaction is marked for rollback only.
public isRollbackOnly ( ) : boolean
Résultat boolean

isTransactionActive() public méthode

Checks whether a transaction is currently active.
public isTransactionActive ( ) : boolean
Résultat boolean TRUE if a transaction is currently active, FALSE otherwise.

lastInsertId() public méthode

Note: This method may not return a meaningful or consistent result across different drivers, because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY columns or sequences.
public lastInsertId ( string | null $seqName = null ) : string
$seqName string | null Name of the sequence object from which the ID should be returned.
Résultat string A string representation of the last inserted ID.

ping() public méthode

When the server is not available the method returns FALSE. It is responsibility of the developer to handle this case and abort the request or reconnect manually:
public ping ( ) : boolean
Résultat boolean

prepare() public méthode

Prepares an SQL statement.
public prepare ( string $statement ) : Statement
$statement string The SQL statement to prepare.
Résultat Statement The prepared statement.

project() public méthode

Executes an, optionally parametrized, SQL query and returns the result, applying a given projection/transformation function on each row of the result.
public project ( string $query, array $params, Closur\Closure $function ) : array
$query string The SQL query to execute.
$params array The parameters, if any.
$function Closur\Closure The transformation function that is applied on each row. The function receives a single parameter, an array, that represents a row of the result set.
Résultat array The projected result of the query.

query() public méthode

Executes an SQL statement, returning a result set as a Statement object.
public query ( ) : Doctrine\DBAL\Driver\Statement
Résultat Doctrine\DBAL\Driver\Statement

quote() public méthode

Quotes a given input parameter.
public quote ( mixed $input, string | null $type = null ) : string
$input mixed The parameter to be quoted.
$type string | null The type of the parameter.
Résultat string The quoted parameter.

quoteIdentifier() public méthode

Delimiting style depends on the underlying database platform that is being used. NOTE: Just because you CAN use quoted identifiers does not mean you SHOULD use them. In general, they end up causing way more problems than they solve.
public quoteIdentifier ( string $str ) : string
$str string The name to be quoted.
Résultat string The quoted name.

releaseSavepoint() public méthode

Releases the given savepoint.
public releaseSavepoint ( string $savepoint ) : void
$savepoint string The name of the savepoint to release.
Résultat void

resolveParams() public méthode

Resolves the parameters to a format which can be displayed.
public resolveParams ( array $params, array $types ) : array
$params array
$types array
Résultat array

rollBack() public méthode

Cancels any database changes done during the current transaction.
public rollBack ( )

rollbackSavepoint() public méthode

Rolls back to the given savepoint.
public rollbackSavepoint ( string $savepoint ) : void
$savepoint string The name of the savepoint to rollback to.
Résultat void

setAutoCommit() public méthode

If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either the method commit or the method rollback. By default, new connections are in auto-commit mode. NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is committed. If this method is called and the auto-commit mode is not changed, the call is a no-op.
See also: isAutoCommit
public setAutoCommit ( boolean $autoCommit )
$autoCommit boolean True to enable auto-commit mode; false to disable it.

setFetchMode() public méthode

Sets the fetch mode.
public setFetchMode ( integer $fetchMode ) : void
$fetchMode integer
Résultat void

setNestTransactionsWithSavepoints() public méthode

Sets if nested transactions should use savepoints.
public setNestTransactionsWithSavepoints ( boolean $nestTransactionsWithSavepoints ) : void
$nestTransactionsWithSavepoints boolean
Résultat void

setRollbackOnly() public méthode

Marks the current transaction so that the only possible outcome for the transaction to be rolled back.
public setRollbackOnly ( ) : void
Résultat void

setTransactionIsolation() public méthode

Sets the transaction isolation level.
public setTransactionIsolation ( integer $level ) : integer
$level integer The level to set.
Résultat integer

transactional() public méthode

The function gets passed this Connection instance as an (optional) parameter. If an exception occurs during execution of the function or transaction commit, the transaction is rolled back and the exception re-thrown.
public transactional ( Closur\Closure $func ) : mixed
$func Closur\Closure The function to execute transactionally.
Résultat mixed The value returned by $func

update() public méthode

Table expression and columns are not escaped and are not safe for user-input.
public update ( string $tableExpression, array $data, array $identifier, array $types = [] ) : integer
$tableExpression string The expression of the table to update quoted or unquoted.
$data array An associative array containing column-value pairs.
$identifier array The update criteria. An associative array containing column-value pairs.
$types array Types of the merged $data and $identifier arrays in that order.
Résultat integer The number of affected rows.

Property Details

$_config protected_oe property

protected Configuration,Doctrine\DBAL $_config
Résultat Doctrine\DBAL\Configuration

$_conn protected_oe property

The wrapped driver connection.
protected Connection,Doctrine\DBAL\Driver $_conn
Résultat Doctrine\DBAL\Driver\Connection

$_driver protected_oe property

The used DBAL driver.
protected Driver,Doctrine\DBAL $_driver
Résultat Doctrine\DBAL\Driver

$_eventManager protected_oe property

protected EventManager,Doctrine\Common $_eventManager
Résultat Doctrine\Common\EventManager

$_expr protected_oe property

protected ExpressionBuilder,Doctrine\DBAL\Query\Expression $_expr
Résultat Doctrine\DBAL\Query\Expression\ExpressionBuilder

$_schemaManager protected_oe property

The schema manager.
protected AbstractSchemaManager,Doctrine\DBAL\Schema $_schemaManager
Résultat Doctrine\DBAL\Schema\AbstractSchemaManager

$defaultFetchMode protected_oe property

protected int $defaultFetchMode
Résultat integer