| Methods |
protected
|
__construct(array<string, mixed> $defaults = [])
|
#
|
public
|
__destruct()
|
#
|
public
|
getConnection(): Connection
|
#
|
public
static
|
normalizeDsn(array<string, string>|string $dsn, string $user = null, string $password = null): array<string, string>
Normalize DSN connection string or DBAL connection params described in:
https://www.doctrine-project.org/projects…
Parameters
| $user |
Optional username, this takes precedence over dsn string
|
| $password |
Optional password, this takes precedence over dsn string
|
|
#
|
public
static
|
registerConnectionClass(class-string<self> $connectionClass, string $driverName): void
Adds connection class to the registry for resolving in Connection::resolve method.
Adds connection class to the registry for resolving in Connection::resolve method.
Can be used as:
Connection::registerConnection(MySQL\Connection::class, 'pdo_mysql')
|
#
|
public
static
|
resolveConnectionClass(string $driverName): class-string<self>
Resolves the connection class to use based on driver type.
Resolves the connection class to use based on driver type.
|
#
|
public
static
|
connect(
string|array<string, string>|Connection|Connection $dsn,
string|null $user = null,
string|null $password = null,
array<string, mixed> $defaults = [],
): self
Connect to database and return connection instance.
Connect to database and return connection instance.
|
#
|
private
static
|
getDriverNameFromDbalDriverConnection(
Connection $connection,
): 'pdo_sqlite'|'pdo_mysql'|'pdo_pgsql'|'pdo_sqlsrv'|'pdo_oci'|'mysqli'|'oci8'
|
#
|
protected
static
|
createDbalConfiguration(): Configuration
|
#
|
protected
static
|
connectFromDsn(array<string, string> $dsn): Connection
|
#
|
protected
static
|
connectFromDbalDriverConnection(Connection $dbalDriverConnection): Connection
|
#
|
public
|
expr(string|array<string, mixed> $template = [], array<mixed> $arguments = []): Expression
Create new Expression with connection already set.
Create new Expression with connection already set.
|
#
|
public
|
dsql(string|array<string, mixed> $defaults = []): Query
Create new Query with connection already set.
Create new Query with connection already set.
|
#
|
public
|
executeQuery(Expression $expr): Result
Execute Expression by using this connection and return result.
Execute Expression by using this connection and return result.
|
#
|
public
|
executeStatement(Expression $expr): int<0, max>
Execute Expression by using this connection and return affected rows.
Execute Expression by using this connection and return affected rows.
|
#
|
public
|
atomic<T>(Closure(): T $fx): T
Atomic executes operations within one begin/end transaction, so if
the code inside callback will fail, then all of the…
Atomic executes operations within one begin/end transaction, so if
the code inside callback will fail, then all of the transaction
will be also rolled back.
|
#
|
public
|
beginTransaction(): void
Starts new transaction.
Starts new transaction.
Database driver supports statements for starting and committing
transactions. Unfortunately most of them don't allow to nest
transactions and commit gradually.
With this method you have some implementation of nested transactions.
When you call it for the first time it will begin transaction. If you
call it more times, it will do nothing but will increase depth counter.
You will need to call commit() for each execution of beginTransactions()
and only the last commit will perform actual commit in database.
So, if you have been working with the database and got un-handled
exception in the middle of your code, everything will be rolled back.
|
#
|
public
|
inTransaction(): bool
Will return true if currently running inside a transaction.
This is useful if you are logging anything into a database.…
Will return true if currently running inside a transaction.
This is useful if you are logging anything into a database. If you are
inside a transaction, don't log or it may be rolled back.
Perhaps use a hook for this?
|
#
|
public
|
commit(): void
Commits transaction.
Commits transaction.
Each occurrence of beginTransaction() must be matched with commit().
Only when same amount of commits are executed, the actual commit will be
issued to the database.
|
#
|
public
|
rollBack(): void
Rollbacks queries since beginTransaction and resets transaction depth.
Rollbacks queries since beginTransaction and resets transaction depth.
|
#
|
public
|
lastInsertId(string $sequence = null): string
Return last inserted ID value.
Return last inserted ID value.
Drivers like PostgreSQL need to receive sequence name to get ID because PDO doesn't support this method.
Overriden by
|
#
|
public
|
getDatabasePlatform(): AbstractPlatform
|
#
|
public
|
createSchemaManager(): AbstractSchemaManager
|
#
|