1 database.inc | public DatabaseTransaction::__construct(DatabaseConnection $connection, $name = NULL) |
Creates a database transaction object.
Parameters
DatabaseConnection $connection: The database connection for this transaction.
string|null $name: An optional name for the transaction. Note these need to be unique within the current transaction stack. Can be left empty to automatically assign a name, but the name can be useful to identify complex series of queries.
Throws
DatabaseTransactionNameNonUniqueException
File
- core/
includes/ database/ database.inc, line 2075 - Core systems for the database layer.
Class
- DatabaseTransaction
- A wrapper class for creating and managing database transactions.
Code
public function __construct(DatabaseConnection $connection, $name = NULL) {
$this->connection = $connection;
// If there is no transaction depth, then no transaction has started. Name
// the transaction 'backdrop_transaction'.
if (!$depth = $connection->transactionDepth()) {
$this->name = 'backdrop_transaction';
}
// Within transactions, savepoints are used. Each savepoint requires a
// name. So if no name is present we need to create one.
elseif (!$name) {
$this->name = 'savepoint_' . $depth;
}
else {
$this->name = $name;
}
$this->connection->pushTransaction($this->name);
}