PDO::beginTransaction starts a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
bool PDO::beginTransaction ( void )
Turn off autocommit mode. When autocommit mode is turned off, changes made to the database through PDO object instances are not committed until PDO::commit() is called to end the transaction.
Calling PDO::rollBack() will roll back changes made to the database and return the database connection to autocommit mode.
Some databases, including MySQL, automatically perform an implicit transaction commit when issuing a DDL statement such as DROP TABLE or CREATE TABLE.
Implicitly committing will prevent you from rolling back any other changes within the scope of this transaction.
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 that any changes in this transaction will not be rolled back.
<?php/* Start a transaction and turn off automatic submission*/$dbh->beginTransaction();/* Change the database structure and data*/$sth = $dbh->exec("DROP TABLE fruit");$sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'");/* Recognize the error and roll back the changes*/$dbh->rollBack();/* The database connection is now back in autocommit mode*/?>