PDO :: rollBack — Rolls back a transaction
public bool PDO::rollBack ( void )
Rolls back the current transaction, as initiated by PDO::beginTransaction().
If the database was set to autocommit mode, this function will restore autocommit mode after it has rolled back the transaction.
Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary.
TRUEon success or
Throws a PDOException if there is no active transaction.
Note: An exception is raised even when the
PDO::ATTR_ERRMODEattribute is not
Example #1 Roll back a transaction
The following example begins a transaction and issues two statements that modify the database before rolling back the changes. On MySQL, however, the DROP TABLE statement automatically commits the transaction so that none of the changes in the transaction are rolled back.
/* Change the database schema and data */
/* Begin a transaction, turning off autocommit */
$sth = $dbh->exec(“DROP TABLE fruit”);
$sth = $dbh->exec(“UPDATE dessert
SET name = ‘hamburger'”);
/* Recognize mistake and roll back changes */
/* Database connection is now back in autocommit mode */