function db_transaction

Returns a new transaction object for the active database.

Parameters

string $name: Optional name of the transaction.

array $options: An array of options to control how the transaction operates:

  • target: The database target name.

Return value

DatabaseTransaction A new DatabaseTransaction object for this connection.

Related topics

6 calls to db_transaction()
field_sql_storage_field_storage_update_field in drupal/core/modules/field_sql_storage/field_sql_storage.module
Implements hook_field_storage_update_field().
menu_router_rebuild in drupal/core/includes/menu.inc
Populates the database tables used by various menu functions.
TransactionTest::testTransactionStacking in drupal/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php
Tests transaction stacking, commit, and rollback.
TransactionTest::testTransactionWithDdlStatement in drupal/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php
Tests the compatibility of transactions with DDL statements.
TransactionTest::transactionInnerLayer in drupal/core/modules/system/lib/Drupal/system/Tests/Database/TransactionTest.php
Creates an "inner layer" transaction.

... See full list

File

drupal/core/includes/database.inc, line 403
Core systems for the database layer.

Code

function db_transaction($name = NULL, array $options = array()) {
  if (empty($options['target'])) {
    $options['target'] = 'default';
  }
  return Database::getConnection($options['target'])
    ->startTransaction($name);
}