1 database.inc public DatabaseConnection_mysql::rollback($savepoint_name = 'backdrop_transaction')

Rolls back the transaction entirely or to a named savepoint.

This method throws an exception if no transaction is active.

Parameters

$savepoint_name: The name of the savepoint. The default, 'backdrop_transaction', will roll the entire transaction back.

Return value

NULL:

Throws

DatabaseTransactionNoActiveException

DatabaseTransactionOutOfOrderException

Overrides DatabaseConnection::rollback

See also

DatabaseTransaction::rollback()

File

core/includes/database/mysql/database.inc, line 339
Database interface code for MySQL database servers.

Class

DatabaseConnection_mysql

Code

public function rollback($savepoint_name = 'backdrop_transaction') {
  // MySQL will automatically commit transactions when tables are altered or
  // created (DDL transactions are not supported). Prevent triggering an
  // exception to ensure that the error that has caused the rollback is
  // properly reported.
  if (!$this->pdo->inTransaction()) {
    // On PHP 7 $this->connection->inTransaction() will return TRUE and
    // $this->connection->rollback() does not throw an exception; the
    // following code is unreachable.

    // If \DatabaseConnection::rollback() would throw an
    // exception then continue to throw an exception.
    if (!$this->inTransaction()) {
      throw new DatabaseTransactionNoActiveException();
    }
    // A previous rollback to an earlier savepoint may mean that the savepoint
    // in question has already been accidentally committed.
    if (!isset($this->transactionLayers[$savepoint_name])) {
      throw new DatabaseTransactionNoActiveException();
    }

    trigger_error('Rollback attempted when there is no active transaction. This can cause data integrity issues.', E_USER_WARNING);
    return;
  }
  return parent::rollback($savepoint_name);
}