Interface Yiisoft\Db\Transaction\TransactionInterface
| Implemented by | Yiisoft\Db\Debug\TransactionInterfaceDecorator, Yiisoft\Db\Driver\Pdo\AbstractPdoTransaction |
|---|
Defines the interface for a database transaction.
A transaction is a set of operations that are executed as a single logical unit of work.
The main benefit of using transactions is that they allow for the atomic, consistent, isolated for many database operations.
The class defines several methods for working with transactions, such as {@see \Yiisoft\Db\Transaction\begin()}, {@see \Yiisoft\Db\Transaction\commit()}, and {@see \Yiisoft\Db\Transaction\rollBack()}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| begin() | Begins a transaction. | Yiisoft\Db\Transaction\TransactionInterface |
| commit() | Commits a transaction. | Yiisoft\Db\Transaction\TransactionInterface |
| createSavepoint() | Creates a new savepoint. | Yiisoft\Db\Transaction\TransactionInterface |
| getLevel() | Yiisoft\Db\Transaction\TransactionInterface | |
| isActive() | Returns a value indicating whether this transaction is active. | Yiisoft\Db\Transaction\TransactionInterface |
| releaseSavepoint() | Releases an existing savepoint. | Yiisoft\Db\Transaction\TransactionInterface |
| rollBack() | Rolls back a transaction. | Yiisoft\Db\Transaction\TransactionInterface |
| rollBackSavepoint() | Rolls back to a before created savepoint. | Yiisoft\Db\Transaction\TransactionInterface |
| setIsolationLevel() | Sets the transaction isolation level for this transaction. | Yiisoft\Db\Transaction\TransactionInterface |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| READ_COMMITTED | 'READ COMMITTED' |
A constant representing the transaction isolation level READ COMMITTED.
|
Yiisoft\Db\Transaction\TransactionInterface |
| READ_UNCOMMITTED | 'READ UNCOMMITTED' |
A constant representing the transaction isolation level READ UNCOMMITTED.
|
Yiisoft\Db\Transaction\TransactionInterface |
| REPEATABLE_READ | 'REPEATABLE READ' |
A constant representing the transaction isolation level REPEATABLE READ.
|
Yiisoft\Db\Transaction\TransactionInterface |
| SERIALIZABLE | 'SERIALIZABLE' |
A constant representing the transaction isolation level SERIALIZABLE.
|
Yiisoft\Db\Transaction\TransactionInterface |
Method Details
Begins a transaction.
| public abstract void begin ( string|null $isolationLevel = null ) | ||
| $isolationLevel | string|null |
The {@see \Yiisoft\Db\Transaction\isolation level}[] to use for this transaction.
This can be one of {@see \Yiisoft\Db\Transaction\READ_UNCOMMITTED}, {@see \Yiisoft\Db\Transaction\READ_COMMITTED}, {@see \Yiisoft\Db\Transaction\REPEATABLE_READ} and {@see \Yiisoft\Db\Transaction\SERIALIZABLE}
but also a string containing DBMS-specific syntax to be used after Note: This setting doesn't work for PostgresSQL, where setting the isolation level before the transaction has no effect. You have to call {@see \Yiisoft\Db\Transaction\setIsolationLevel()} in this case after the transaction has started. Note: Some (DBMS) allow setting of the isolation level only for the whole connection so later transactions may get the same isolation level even if you didn't specify any. When using this feature, you may need to set the isolation level for all transactions explicitly to avoid conflicting settings. At the time of this writing affected DBMS are MSSQL and SQLite. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable |
If DB connection fails or the current transaction is active. |
| throws | Yiisoft\Db\Exception\InvalidConfigException |
If {@see \Yiisoft\Db\Connection\ConnectionInterface} is |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If the DBMS doesn't support nested transactions or the transaction is active. |
public function begin(?string $isolationLevel = null): void;
Commits a transaction.
| public abstract void commit ( ) | ||
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable |
If the transaction isn't active |
public function commit(): void;
Creates a new savepoint.
| public abstract void createSavepoint ( string $name ) | ||
| $name | string |
The savepoint name. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function createSavepoint(string $name): void;
| public abstract integer getLevel ( ) | ||
| return | integer |
The nesting level of the transaction. 0 means the outermost level. |
|---|---|---|
public function getLevel(): int;
Returns a value indicating whether this transaction is active.
| public abstract boolean isActive ( ) | ||
| return | boolean |
Whether this transaction is active. Only an active transaction can {@see \Yiisoft\Db\Transaction\commit()} or {@see \Yiisoft\Db\Transaction\rollBack()}. |
|---|---|---|
public function isActive(): bool;
Releases an existing savepoint.
| public abstract void releaseSavepoint ( string $name ) | ||
| $name | string |
The savepoint name. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function releaseSavepoint(string $name): void;
Rolls back a transaction.
| public abstract void rollBack ( ) | ||
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function rollBack(): void;
Rolls back to a before created savepoint.
| public abstract void rollBackSavepoint ( string $name ) | ||
| $name | string |
The savepoint name. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function rollBackSavepoint(string $name): void;
Sets the transaction isolation level for this transaction.
You can use this method to set the isolation level while the transaction is already active. However, this isn't supported by all DBMS, so you might rather specify the isolation level directly when calling {@see \Yiisoft\Db\Transaction\begin()}.
| public abstract void setIsolationLevel ( string $level ) | ||
| $level | string |
The transaction isolation level to use for this transaction.
This can be one of {@see \Yiisoft\Db\Transaction\READ_UNCOMMITTED}, {@see \Yiisoft\Db\Transaction\READ_COMMITTED}, {@see \Yiisoft\Db\Transaction\REPEATABLE_READ} and {@see \Yiisoft\Db\Transaction\SERIALIZABLE}
but also a string containing DBMS-specific syntax to be used after |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable |
If the transaction isn't active. |
public function setIsolationLevel(string $level): void;
Signup or Login in order to comment.