Skip to content
PHP Ecosystem
Explore

Transaction

API reference › yii › db › pgsql › Transaction

classyii\db\pgsql\Transaction
Extendsyii\db\Transaction » yii\base\BaseObject
Implementsyii\base\Configurable
Since22.0
Sourceframework/db/pgsql/Transaction.php

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.

PropertyTypeDescriptionDefined by
$dbyii\db\ConnectionThe database connection that this transaction is associated with. Default: null.yii\db\Transaction
$isActive read-onlyboolWhether this transaction is active.yii\db\Transaction
$isolationLevel write-onlystringThe transaction isolation level to use for this transaction.yii\db\Transaction
$level read-onlyintThe current nesting level of the transaction.yii\db\Transaction
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
begin()Begins a transaction.Transaction
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
commit()Commits a transaction.yii\db\Transaction
getIsActive()Returns a value indicating whether this transaction is active.yii\db\Transaction
getLevel()yii\db\Transaction
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
rollBack()Rolls back a transaction.yii\db\Transaction
setIsolationLevel()Sets the transaction isolation level for this transaction.yii\db\Transaction
ConstantValueDescriptionDefined by
READ_UNCOMMITTED'READ UNCOMMITTED'A constant representing the transaction isolation level READ UNCOMMITTED.yii\db\Transaction
READ_COMMITTED'READ COMMITTED'A constant representing the transaction isolation level READ COMMITTED.yii\db\Transaction
REPEATABLE_READ'REPEATABLE READ'A constant representing the transaction isolation level REPEATABLE READ.yii\db\Transaction
SERIALIZABLE'SERIALIZABLE'A constant representing the transaction isolation level SERIALIZABLE.yii\db\Transaction
public function begin(mixed $isolationLevel = null): mixed

Begins a transaction.

Parameters

ParameterTypeDescription
$isolationLevelmixedThe [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