db_transaction

Definition

db_transaction($required = FALSE, Array $options = array())
drupal/includes/database/database.inc, line 2339

Description

Returns a new transaction object for the active database.

Parameters

$required TRUE if the calling code will not function properly without transaction support. If set to TRUE and the active database does not support transactions, a TransactionsNotSupportedException exception will be thrown.

$options An array of options to control how the transaction operates. Only the target key has any meaning in this case.

Return value

DatabaseTransaction A new DatabaseTransaction object for this connection.

Related topics

Namesort iconDescription
Database abstraction layerAllow the use of different database servers using the same code base.

Code

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