W3cubDocs

/Drupal 8

class Transaction

A wrapper class for creating and managing database transactions.

Not all databases or database configurations support transactions. For example, MySQL MyISAM tables do not. It is also easy to begin a transaction and then forget to commit it, which can lead to connection errors when another transaction is started.

This class acts as a wrapper for transactions. To begin a transaction, simply instantiate it. When the object goes out of scope and is destroyed it will automatically commit. It also will check to see if the specified connection supports transactions. If not, it will simply skip any transaction commands, allowing user-space code to proceed normally. The only difference is that rollbacks won't actually do anything.

In the vast majority of cases, you should not instantiate this class directly. Instead, call ->startTransaction(), from the appropriate connection object.

Hierarchy

File

core/lib/Drupal/Core/Database/Transaction.php, line 24

Namespace

Drupal\Core\Database

Members

Name Modifiers Type Description
Transaction::$connection protected property The connection object for this transaction.
Transaction::$name protected property The name of the transaction.
Transaction::$rolledBack protected property A boolean value to indicate whether this transaction has been rolled back.
Transaction::name public function Retrieves the name of the transaction or savepoint.
Transaction::rollback public function Rolls back the current transaction.
Transaction::__construct public function
Transaction::__destruct public function

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Transaction.php/class/Transaction/8.1.x