Transaction
API reference › yii › db › pgsql › Transaction
Represents a PostgreSQL DB transaction.
PostgreSQL discards SET TRANSACTION issued outside a transaction block, so the isolation level is applied through
setIsolationLevel() right after the transaction starts, and the transaction is rolled back if the level is
rejected.
See also: https://www.postgresql.org/docs/current/sql-set-transaction.html.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$db | yii\ | The database connection that this transaction is associated with. Default: null. | yii\ |
$isActive read-only | bool | Whether this transaction is active. | yii\ |
$isolationLevel write-only | string | The transaction isolation level to use for this transaction. | yii\ |
$level read-only | int | The current nesting level of the transaction. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
begin() | Begins a transaction. | Transaction |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
commit() | Commits a transaction. | yii\ |
getIsActive() | Returns a value indicating whether this transaction is active. | yii\ |
getLevel() | yii\ | |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
rollBack() | Rolls back a transaction. | yii\ |
setIsolationLevel() | Sets the transaction isolation level for this transaction. | yii\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
READ_UNCOMMITTED | 'READ UNCOMMITTED' | A constant representing the transaction isolation level READ UNCOMMITTED. | yii\ |
READ_COMMITTED | 'READ COMMITTED' | A constant representing the transaction isolation level READ COMMITTED. | yii\ |
REPEATABLE_READ | 'REPEATABLE READ' | A constant representing the transaction isolation level REPEATABLE READ. | yii\ |
SERIALIZABLE | 'SERIALIZABLE' | A constant representing the transaction isolation level SERIALIZABLE. | yii\ |
Method details
Section titled “Method details”begin()
Section titled “begin() ”public function begin(mixed $isolationLevel = null): mixedBegins a transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
$isolationLevel | mixed | The [isolation level][] to use for this transaction. This can be one of READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ and SERIALIZABLE but also a string containing DBMS specific syntax to be used after SET TRANSACTION ISOLATION LEVEL. If not specified (null) the isolation level will not be set explicitly and the DBMS default will be used. > Note: Some DBMS allow setting of the isolation level only for the whole connection so subsequent transactions may get the same isolation level even if you did not 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. > Note: The isolation level applies to the outermost transaction only. Nested transactions are implemented with savepoints and always run at the isolation level of the outer transaction, so an $isolationLevel passed to a nested begin() call is ignored and a warning is logged (since 2.0.56). [isolation level]: https://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels Starting from version 2.0.16, this method throws exception when beginning nested transaction and underlying DBMS does not support savepoints. |
Returns
mixed
Throws
yii\base\InvalidConfigException: if$dbisnullyii\base\NotSupportedException: if the DBMS does not support nested transactionsyii\db\Exception: if DB connection fails