Methods |
public
|
getDatabase(): string
Gets the name of the database this Connection is connected to.
Gets the name of the database this Connection is connected to.
|
#
|
public
|
getHost(): string|null
Gets the hostname of the currently connected database.
Gets the hostname of the currently connected database.
|
#
|
public
|
getPort(): mixed
Gets the port of the currently connected database.
Gets the port of the currently connected database.
|
#
|
public
|
getUsername(): string|null
Gets the username used by this connection.
Gets the username used by this connection.
|
#
|
public
|
getPassword(): string|null
Gets the password used by this connection.
Gets the password used by this connection.
|
#
|
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
|
getExpressionBuilder(): ExpressionBuilder
Gets the ExpressionBuilder for the connection.
Gets the ExpressionBuilder for the connection.
|
#
|
public
|
connect(): bool
Establishes the connection with the database.
Establishes the connection with the database.
Returns
TRUE if the connection was successfully established, FALSE if
the connection is already open.
|
#
|
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
|
setFetchMode(int $fetchMode): void
Sets the fetch mode.
Deprecated
Use one of the fetch- or iterate-related methods.
|
#
|
public
|
fetchAssoc(
string $sql,
array<int, 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.
Deprecated
Parameters
$sql |
SQL query
|
$params |
Query parameters
|
$types |
Parameter types
|
Returns
False is returned if no rows are found.
Throws
|
#
|
public
|
fetchArray(
string $sql,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<int, 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.
Deprecated
Parameters
$sql |
SQL query
|
$params |
Query parameters
|
$types |
Parameter types
|
Returns
False is returned if no rows are found.
|
#
|
public
|
fetchColumn(
string $sql,
array<int, mixed>|array<string, mixed> $params = [],
int $column = 0,
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.
Deprecated
Parameters
$sql |
SQL query
|
$params |
Query parameters
|
$column |
0-indexed column number
|
$types |
Parameter types
|
Returns
False is returned if no rows are found.
Throws
|
#
|
public
|
fetchAssociative(
string $query,
array<int, 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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<int, 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,
array<int, 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.
|
#
|
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(int $level): int|string
Sets the transaction isolation level.
Sets the transaction isolation level.
Parameters
|
#
|
public
|
getTransactionIsolation(): int
Gets the currently active transaction isolation level.
Gets the currently active transaction isolation level.
Returns
The current transaction isolation level.
|
#
|
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
|
#
|
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)
{@inheritDoc}
|
#
|
public
|
fetchAll(string $sql, mixed[] $params = [], int[]|string[] $types = []): mixed[]
Prepares and executes an SQL query and returns the result as an associative array.
Prepares and executes an SQL query and returns the result as an associative array.
Deprecated
Use fetchAllAssociative()
Parameters
$sql |
The SQL query.
|
$params |
The query parameters.
|
$types |
The query parameter types.
|
|
#
|
public
|
fetchAllNumeric(
string $query,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<int, array<int, 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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<int, 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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string>|array<string, int|string> $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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string>|array<string, int|string> $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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): array<int, 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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): Traversable<int, array<int, 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,
array<int, 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,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string>|array<string, int|string> $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,
array<int, 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,
array<int, 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.
|
Returns
Throws
Implements
|
#
|
public
|
executeQuery(
string $sql,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
?QueryCacheProfile $qcp = null,
): DriverStatement|DriverResultStatement
Executes an, optionally parametrized, SQL query.
Executes an, optionally parametrized, 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,
array<int, mixed>|array<string, mixed> $params,
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types,
QueryCacheProfile $qcp,
): DriverResultStatement
Executes a caching query.
Executes a caching query.
Parameters
$sql |
SQL query
|
$params |
Query parameters
|
$types |
Parameter types
|
Throws
|
#
|
public
|
project(string $sql, mixed[] $params, Closure $function): mixed[]
Executes an, optionally parametrized, SQL query and returns the result,
applying a given projection/transformation…
Executes an, optionally parametrized, SQL query and returns the result,
applying a given projection/transformation function on each row of the result.
Parameters
$sql |
The SQL query to execute.
|
$params |
The parameters, if any.
|
$function |
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.
|
Returns
The projected result of the query.
|
#
|
public
|
query(): Statement
Executes an SQL statement, returning a result set as a Statement object.
Executes an SQL statement, returning a result set as a Statement object.
Deprecated
Use {@link executeQuery()} instead.
Throws
Implements
|
#
|
public
|
executeUpdate(
string $sql,
array<int, mixed>|array<string, mixed> $params = [],
array<int, int|string|Type|null>|array<string, int|string|Type|null> $types = [],
): int|string
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
and returns the number of affected rows.
Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
and returns the number of affected rows.
This method supports PDO binding types as well as DBAL mapping types.
Deprecated
Use {@link executeStatement()} instead.
Parameters
$sql |
SQL statement
|
$params |
Statement parameters
|
$types |
Parameter types
|
Returns
The number of affected rows.
Throws
|
#
|
public
|
executeStatement(
string $sql,
array<int, 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
|
exec(string $sql): int|string
Executes an SQL statement and return the number of affected rows.
Executes an SQL statement and return the number of affected rows.
Deprecated
Use {@link executeStatement()} instead.
Returns
The number of affected rows.
Throws
Implements
|
#
|
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
|
errorCode(): string|null
Fetches the SQLSTATE associated with the last database operation.
Fetches the SQLSTATE associated with the last database operation.
Deprecated
The error information is available via exceptions.
Returns
Implements
|
#
|
public
|
errorInfo()
{@inheritDoc}
Deprecated
The error information is available via exceptions.
Implements
|
#
|
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.
Implements
|
#
|
public
|
transactional(Closure $func): mixed
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.
|
#
|
public
|
beginTransaction()
{@inheritDoc}
Returns
TRUE on success or FALSE on failure.
Implements
|
#
|
public
|
commit()
{@inheritDoc}
Returns
TRUE on success or FALSE on failure.
Throws
Implements
|
#
|
public
|
rollBack(): bool
Cancels any database changes done during the current transaction.
Cancels any database changes done during the current transaction.
Returns
TRUE on success or FALSE on failure.
Throws
Implements
|
#
|
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.
|
#
|
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.
|
#
|
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
|
#
|
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
|
#
|
public
|
createQueryBuilder(): QueryBuilder
Creates a new instance of a SQL query builder.
Creates a new instance of a SQL query builder.
|
#
|
public
|
ping(): bool
Ping the server
Ping the server
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:
|
#
|