PDO::rollBack — Roll back a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
bool PDO::rollBack ( void )
Rollback the current transaction initiated by PDO::beginTransaction(). If no transaction is active, a PDOException will be thrown.
If the database is set to autocommit mode, this function (method) will restore autocommit mode after rolling back the transaction.
Some databases, including MySQL, automatically cause an implicit commit when there are DLL statements such as deleting or creating a data table within a transaction. Implicitly committing will not be able to roll back any changes within the scope of this transaction.
Returns TRUE on success, or FALSE on failure.
The following example starts a transaction and issues two statements that modify the database before rolling back the changes. But in MySQL, the DROP TABLE statement automatically commits the transaction, so any changes within this transaction will not be rolled back.
<?php/* Start a transaction and turn off auto-commit*/$dbh->beginTransaction();/* Change the database schema and data*/$sth = $dbh->exec("DROP TABLE fruit");$sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'");/* Recognize errors and roll back changes*/$dbh->rollBack();/* At this point the database connection returns to auto-commit mode*/?>