YouTip LogoYouTip

Pdo Begintransaction

# PDO::beginTransaction [![Image 3: PHP PDO Reference](#)PHP PDO Reference](#) PDO::beginTransaction starts a transaction (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0) * * * ## Description ### Syntax bool PDO::beginTransaction ( void ) Disables autocommit mode. While autocommit mode is disabled, changes made to the database via the PDO object instance are not committed until you call PDO::commit() to end the transaction. Calling PDO::rollBack() will roll back the changes made to the database and return the database connection to autocommit mode. Some databases, including MySQL, will automatically perform an implicit commit when issuing a DDL statement like DROP TABLE or CREATE TABLE. An implicit commit will prevent you from rolling back any other changes within this transaction scope. * * * ## Return Value Returns TRUE on success or FALSE on failure. * * * ## Examples ### Rolling Back a Transaction The following example starts a transaction and issues two statements that modify the database before rolling back the changes. However, in MySQL, the DROP TABLE statement automatically commits the transaction, making any changes within this transaction non-rollbackable. beginTransaction();/* Modify the database schema and data */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'");/* Identify an error and roll back the changes */ $dbh->rollBack();/* The database connection is now back in autocommit mode */?> * * PHP PDO Reference](#)
← Pdo CommitPhp Pdo Lobs β†’