Transactions are done the through the PDO database connection using beginTransaction, commit and rollback. To use transactions, you must use a database engine that supports them, (such as InnoDB for MySQL). To access the PDO connection, use DBManager::getConnection() or the static getConnection() method on any of the generated classes.
require_once('config.php');
//get the PDO connection for the database with the table "Book"
//If you have an early version of DABL, you my need to use DB::getConnection()
$conn = Book::getConnection();
//begin transaction
$conn->beginTransaction();
//get Book with ID of 32
$b = Book::retrieveByPK(32);
try{
//delete the book and commit the transaction
$b->delete();
$conn->commit();
}
//rollback the transaction of there is an Exception
catch(Exception $e){
$conn->rollback();
}
?>
(503) 746-9116 | 17933 NW Evergreen Parkway, Suite 220 | Beaverton, Oregon 97006