PDO::beginTransaction

(no version information, might be only in CVS)

PDO::beginTransaction --  Initiates a transaction

Description

bool PDO::beginTransaction ( void )

Warning

This function is EXPERIMENTAL. The behaviour of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk.

Turns off autocommit mode. Call PDO::commit() or PDO::rollback() to end the transaction and return to autocommit mode.

Examples

Example 1. Roll back a transaction

<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();

/* Change the database schema and data */
$sth = $dbh->exec("DROP TABLE fruit");
$sth = $dbh->exec("UPDATE dessert
    SET name = 'hamburger'"
);

/* Recognize mistake and roll back changes */
$dbh->rollBack();

/* Database connection is now back in autocommit mode */
?>

See Also

PDO::commit()
PDO::rollBack()