| Methods |
public
|
getDatabase(): string|null
Gets the name of the currently selected database.
Gets the name of the currently selected database.
Returns
The name of the database or NULL if a database is not selected.
The platforms which don't support the concept of a database (e.g. embedded databases)
must always return a string as an indicator of an implicitly selected database.
Throws
|
#
|
public
|
getDriver(): Driver
Gets the DBAL driver instance.
Gets the DBAL driver instance.
|
#
|
public
|
getConfiguration(): Configuration
Gets the Configuration used by the Connection.
Gets the Configuration used by the Connection.
|
#
|
public
|
getEventManager(): EventManager
Gets the EventManager used by the Connection.
Gets the EventManager used by the Connection.
|
#
|
public
|
getDatabasePlatform(): AbstractPlatform
Gets the DatabasePlatform for the connection.
Gets the DatabasePlatform for the connection.
Throws
|
#
|
public
|
createExpressionBuilder(): ExpressionBuilder
Creates an expression builder for the connection.
Creates an expression builder for the connection.
|
#
|
public
|
getExpressionBuilder(): ExpressionBuilder
Gets the ExpressionBuilder for the connection.
Gets the ExpressionBuilder for the connection.
Deprecated
Use {@see createExpressionBuilder()} instead.
|
#
|
private
|
detectDatabasePlatform(): AbstractPlatform
Detects and sets the database platform.
Detects and sets the database platform.
Evaluates custom platform class and version in order to set the correct platform.
Throws
|
#
|
private
|
getDatabasePlatformVersion(): string|null
Returns the version of the related platform if applicable.
Returns the version of the related platform if applicable.
Returns null if either the driver is not capable to create version
specific platform instances, no explicit server version was specified
or the underlying driver connection cannot determine the platform
version without having to query it (performance reasons).
Throws
|
#
|
private
|
getServerVersion(): string|null
Returns the database server version if the underlying driver supports it.
Returns the database server version if the underlying driver supports it.
Throws
|
#
|
public
|
isAutoCommit(): bool
Returns the current auto-commit mode for this connection.
Returns the current auto-commit mode for this connection.
Returns
True if auto-commit mode is currently enabled for this connection, false otherwise.
|
#
|
public
|
setAutoCommit(bool $autoCommit): void
Sets auto-commit mode for this connection.
Sets auto-commit mode for this connection.
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.
Parameters
| $autoCommit |
True to enable auto-commit mode; false to disable it.
|
|
#
|
public
|
fetchAssociative(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<string, mixed>|false
Prepares and executes an SQL query and returns the first row of the result
as an associative array.
Prepares and executes an SQL query and returns the first row of the result
as an associative array.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Returns
False is returned if no rows are found.
Throws
|
#
|
public
|
fetchNumeric(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): list<mixed>|false
Prepares and executes an SQL query and returns the first row of the result
as a numerically indexed array.
Prepares and executes an SQL query and returns the first row of the result
as a numerically indexed array.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Returns
False is returned if no rows are found.
Throws
|
#
|
public
|
fetchOne(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): mixed|false
Prepares and executes an SQL query and returns the value of a single column
of the first row of the result.
Prepares and executes an SQL query and returns the value of a single column
of the first row of the result.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Returns
False is returned if no rows are found.
Throws
|
#
|
public
|
isConnected(): bool
Whether an actual connection to the database is established.
Whether an actual connection to the database is established.
|
#
|
public
|
isTransactionActive(): bool
Checks whether a transaction is currently active.
Checks whether a transaction is currently active.
Returns
TRUE if a transaction is currently active, FALSE otherwise.
|
#
|
private
|
addCriteriaCondition(array<string, mixed> $criteria, string[] &$columns, mixed[] &$values, string[] &$conditions): void
Adds condition based on the criteria to the query components
Adds condition based on the criteria to the query components
Parameters
| $criteria |
Map of key columns to their values
|
| $columns |
Column names
|
| $values |
Column values
|
| $conditions |
Key conditions
|
Throws
|
#
|
public
|
delete(
string $table,
array<string, mixed> $criteria,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): int|string
Executes an SQL DELETE statement on a table.
Executes an SQL DELETE statement on a table.
Table expression and columns are not escaped and are not safe for user-input.
Parameters
| $table |
Table name
|
| $criteria |
Deletion criteria
|
| $types |
Parameter types
|
Returns
The number of affected rows.
Throws
|
#
|
public
|
close(): void
Closes the connection.
|
#
|
public
|
setTransactionIsolation(TransactionIsolationLevel::* $level): int|string
Sets the transaction isolation level.
Sets the transaction isolation level.
Parameters
Throws
|
#
|
public
|
getTransactionIsolation(): TransactionIsolationLevel::*
Gets the currently active transaction isolation level.
Gets the currently active transaction isolation level.
Returns
The current transaction isolation level.
Throws
|
#
|
public
|
update(
string $table,
array<string, mixed> $data,
array<string, mixed> $criteria,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): int|string
Executes an SQL UPDATE statement on a table.
Executes an SQL UPDATE statement on a table.
Table expression and columns are not escaped and are not safe for user-input.
Parameters
| $table |
Table name
|
| $data |
Column-value pairs
|
| $criteria |
Update criteria
|
| $types |
Parameter types
|
Returns
The number of affected rows.
Throws
|
#
|
public
|
insert(
string $table,
array<string, mixed> $data,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): int|string
Inserts a table row with specified data.
Inserts a table row with specified data.
Table expression and columns are not escaped and are not safe for user-input.
Parameters
| $table |
Table name
|
| $data |
Column-value pairs
|
| $types |
Parameter types
|
Returns
The number of affected rows.
Throws
|
#
|
private
|
extractTypeValues(
array<int, string> $columnList,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types,
): array<int, int|string|Type|null>|array<string, int|string|Type|null>
Extract ordered type list from an ordered column list and type map.
Extract ordered type list from an ordered column list and type map.
|
#
|
public
|
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.
Quotes a string so it can be safely used as a table or column name, even if
it is a reserved name.
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.
Parameters
| $str |
The name to be quoted.
|
Returns
|
#
|
public
|
quote(mixed $value, int|string|Type|null $type = ParameterType::STRING): mixed
The usage of this method is discouraged. Use prepared statements
or {@see AbstractPlatform::quoteStringLiteral()}…
The usage of this method is discouraged. Use prepared statements
or {@see AbstractPlatform::quoteStringLiteral()} instead.
|
#
|
public
|
fetchAllNumeric(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): list<list<mixed>>
Prepares and executes an SQL query and returns the result as an array of numeric arrays.
Prepares and executes an SQL query and returns the result as an array of numeric arrays.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
fetchAllAssociative(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): list<array<string, mixed>>
Prepares and executes an SQL query and returns the result as an array of associative arrays.
Prepares and executes an SQL query and returns the result as an array of associative arrays.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
fetchAllKeyValue(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<mixed, mixed>
Prepares and executes an SQL query and returns the result as an associative array with the keys
mapped to the first…
Prepares and executes an SQL query and returns the result as an associative array with the keys
mapped to the first column and the values mapped to the second column.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
fetchAllAssociativeIndexed(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<mixed, array<string, mixed>>
Prepares and executes an SQL query and returns the result as an associative array with the keys mapped
to the first…
Prepares and executes an SQL query and returns the result as an associative array with the keys mapped
to the first column and the values being an associative array representing the rest of the columns
and their values.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
fetchFirstColumn(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): list<mixed>
Prepares and executes an SQL query and returns the result as an array of the first column values.
Prepares and executes an SQL query and returns the result as an array of the first column values.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
iterateNumeric(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): Traversable<int, list<mixed>>
Prepares and executes an SQL query and returns the result as an iterator over rows represented as numeric arrays.
Prepares and executes an SQL query and returns the result as an iterator over rows represented as numeric arrays.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
iterateAssociative(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): Traversable<int, array<string, mixed>>
Prepares and executes an SQL query and returns the result as an iterator over rows represented
as associative arrays.
Prepares and executes an SQL query and returns the result as an iterator over rows represented
as associative arrays.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
iterateKeyValue(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): Traversable<mixed, mixed>
Prepares and executes an SQL query and returns the result as an iterator with the keys
mapped to the first column and…
Prepares and executes an SQL query and returns the result as an iterator with the keys
mapped to the first column and the values mapped to the second column.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
iterateAssociativeIndexed(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string>|array<string, int|string> $types = [],
): Traversable<mixed, array<string, mixed>>
Prepares and executes an SQL query and returns the result as an iterator with the keys mapped
to the first column and…
Prepares and executes an SQL query and returns the result as an iterator with the keys mapped
to the first column and the values being an associative array representing the rest of the columns
and their values.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
iterateColumn(
string $query,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): Traversable<int, mixed>
Prepares and executes an SQL query and returns the result as an iterator over the first column values.
Prepares and executes an SQL query and returns the result as an iterator over the first column values.
Parameters
| $query |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
prepare(string $sql): Statement
Prepares an SQL statement.
Prepares an SQL statement.
Parameters
| $sql |
The SQL statement to prepare.
|
Throws
|
#
|
public
|
executeQuery(
string $sql,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
?QueryCacheProfile $qcp = null,
): Result
Executes an, optionally parameterized, SQL query.
Executes an, optionally parameterized, SQL query.
If the query is parametrized, a prepared statement is used.
If an SQLLogger is configured, the execution is logged.
Parameters
| $sql |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
executeCacheQuery(
string $sql,
list<mixed>|array<string, mixed> $params,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types,
QueryCacheProfile $qcp,
): Result
Executes a caching query.
Executes a caching query.
Parameters
| $sql |
SQL query
|
| $params |
Query parameters
|
| $types |
Parameter types
|
Throws
|
#
|
public
|
executeStatement(
string $sql,
list<mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): int|string
Executes an SQL statement with the given parameters and returns the number of affected rows.
Executes an SQL statement with the given parameters and returns the number of affected rows.
Could be used for:
- DML statements: INSERT, UPDATE, DELETE, etc.
- DDL statements: CREATE, DROP, ALTER, etc.
- DCL statements: GRANT, REVOKE, etc.
- Session control statements: ALTER SESSION, SET, DECLARE, etc.
- Other statements that don't yield a row set.
This method supports PDO binding types as well as DBAL mapping types.
Parameters
| $sql |
SQL statement
|
| $params |
Statement parameters
|
| $types |
Parameter types
|
Returns
The number of affected rows.
Throws
|
#
|
public
|
getTransactionNestingLevel(): int
Returns the current transaction nesting level.
Returns the current transaction nesting level.
Returns
The nesting level. A value of 0 means there's no active transaction.
|
#
|
public
|
lastInsertId(string|null $name = null): string|int|false
Returns the ID of the last inserted row, or the last value from a sequence object,
depending on the underlying driver.
Returns the ID of the last inserted row, or the last value from a sequence object,
depending on the underlying driver.
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.
Parameters
| $name |
Name of the sequence object from which the ID should be returned.
|
Returns
A string representation of the last inserted ID.
Throws
|
#
|
public
|
transactional<T>(Closure(self): T $func): T
Executes a function in a transaction.
Executes a function in a transaction.
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.
Parameters
| $func |
The function to execute transactionally.
|
Returns
The value returned by $func
Throws
|
#
|
public
|
setNestTransactionsWithSavepoints(bool $nestTransactionsWithSavepoints): void
Sets if nested transactions should use savepoints.
Sets if nested transactions should use savepoints.
Throws
|
#
|
public
|
getNestTransactionsWithSavepoints(): bool
Gets if nested transactions should use savepoints.
Gets if nested transactions should use savepoints.
|
#
|
protected
|
_getNestedTransactionSavePointName(): string
Returns the savepoint name to use for nested transactions.
Returns the savepoint name to use for nested transactions.
|
#
|
public
|
beginTransaction(): bool
|
#
|
public
|
commit(): bool
|
#
|
private
|
doCommit(Connection $connection): bool
|
#
|
private
|
commitAll(): void
Commits all current nesting transactions.
Commits all current nesting transactions.
Throws
|
#
|
public
|
rollBack(): bool
Cancels any database changes done during the current transaction.
Cancels any database changes done during the current transaction.
Throws
|
#
|
public
|
createSavepoint(string $savepoint): void
Creates a new savepoint.
Parameters
| $savepoint |
The name of the savepoint to create.
|
Throws
|
#
|
public
|
releaseSavepoint(string $savepoint): void
Releases the given savepoint.
Releases the given savepoint.
Parameters
| $savepoint |
The name of the savepoint to release.
|
Throws
|
#
|
public
|
rollbackSavepoint(string $savepoint): void
Rolls back to the given savepoint.
Rolls back to the given savepoint.
Parameters
| $savepoint |
The name of the savepoint to rollback to.
|
Throws
|
#
|
public
|
getWrappedConnection(): Connection
Gets the wrapped driver connection.
Gets the wrapped driver connection.
Deprecated
Use {@link getNativeConnection()} to access the native connection.
Throws
|
#
|
public
|
getNativeConnection(): resource|object
|
#
|
public
|
createSchemaManager(): AbstractSchemaManager
Creates a SchemaManager that can be used to inspect or change the
database schema through the connection.
Creates a SchemaManager that can be used to inspect or change the
database schema through the connection.
Throws
|
#
|
public
|
getSchemaManager(): AbstractSchemaManager
Gets the SchemaManager that can be used to inspect or change the
database schema through the connection.
Gets the SchemaManager that can be used to inspect or change the
database schema through the connection.
Deprecated
Use {@see createSchemaManager()} instead.
Throws
|
#
|
public
|
setRollbackOnly(): void
Marks the current transaction so that the only possible
outcome for the transaction to be rolled back.
Marks the current transaction so that the only possible
outcome for the transaction to be rolled back.
Throws
|
#
|
public
|
isRollbackOnly(): bool
Checks whether the current transaction is marked for rollback only.
Checks whether the current transaction is marked for rollback only.
Throws
|
#
|
public
|
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.
Converts a given value to its database representation according to the conversion
rules of a specific DBAL mapping type.
Parameters
| $value |
The value to convert.
|
| $type |
The name of the DBAL mapping type.
|
Returns
Throws
|
#
|
public
|
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.
Converts a given value to its PHP representation according to the conversion
rules of a specific DBAL mapping type.
Parameters
| $value |
The value to convert.
|
| $type |
The name of the DBAL mapping type.
|
Returns
Throws
|
#
|
private
|
bindParameters(
Statement $stmt,
list<mixed>|array<string, mixed> $params,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $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…
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.
Parameters
| $stmt |
Prepared statement
|
| $params |
Statement parameters
|
| $types |
Parameter types
|
Throws
|
#
|
private
|
getBindingInfo(mixed $value, int|string|Type|null $type): array{mixed, int}
Gets the binding type of a given type.
Gets the binding type of a given type.
Parameters
| $value |
The value to bind.
|
| $type |
The type to bind (PDO or DBAL).
|
Returns
[0] => the (escaped) value, [1] => the binding type.
Throws
|
#
|
public
|
createQueryBuilder(): QueryBuilder
Creates a new instance of a SQL query builder.
Creates a new instance of a SQL query builder.
|
#
|
private
|
expandArrayParameters(
string $sql,
array<int, mixed>|array<string, mixed> $params,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types,
): array{string, list<mixed>, array<int, Type|int|string|null>}
|
#
|
private
|
needsArrayParameterConversion(
array<int, mixed>|array<string, mixed> $params,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types,
): bool
|
#
|
private
|
handleDriverException(Exception $driverException, ?Query $query): DriverException
|
#
|
public
|
executeUpdate(string $sql, array<mixed> $params = [], array<int|string|null> $types = []): int
BC layer for a wide-spread use-case of old DBAL APIs
BC layer for a wide-spread use-case of old DBAL APIs
Deprecated
Use {@see executeStatement()} instead
Parameters
| $params |
The query parameters
|
| $types |
The parameter types
|
|
#
|
public
|
query(string $sql): Result
BC layer for a wide-spread use-case of old DBAL APIs
BC layer for a wide-spread use-case of old DBAL APIs
Deprecated
Use {@see executeQuery()} instead
|
#
|
public
|
exec(string $sql): int
BC layer for a wide-spread use-case of old DBAL APIs
BC layer for a wide-spread use-case of old DBAL APIs
Deprecated
please use {@see executeStatement()} instead
|
#
|