PDO :: rollBack
PDO :: rollBack - to roll back a transaction (PHP 5> = 5.1.0, PECL pdo> = 0.1.0)
Explanation
grammar
bool PDO::rollBack ( void )
Rollback the current transaction by the PDO :: beginTransaction () initiated. If no transaction is active, it will throw an exception PDOException.
If the database is set to auto-commit mode, this function (method) will be restored after the transaction is rolled back auto-commit mode.
Some databases including MySQL, when a transaction similar to delete or create data tables, etc. DLL statement, it will automatically lead to an implicit commit. Implicitly submitted will not be able to roll back any changes within the scope of this transaction.
return value
Successful return TRUE, or on failure returns FALSE.
Examples
Roll back a transaction
The following example rolls back the changes before the beginning of a transaction and issues two statements that modify the database. However, in MySQL, DROP TABLE statement automatically commits the transaction, so any changes in this transaction will not be rolled back.
<?php /* 开始一个事务,关闭自动提交 */ $dbh->beginTransaction(); /* 更改数据库架构和数据 */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'"); /* 识别错误且回滚更改 */ $dbh->rollBack(); /* 此时数据库连接恢复到自动提交模式 */ ?>