$db->beginTransaction(); try { $db->query("INSERT INTO customers VALUES (1, 'John Doe')"); $db->query("INSERT INTO orders VALUES (1, 1, 100.00)"); // some other code here $db->commit(); } catch (Exception $e) { $db->rollback_transaction(); }In this example, we begin a transaction and make some changes to the database. If all changes are successful, we commit the transaction. However, if an exception is thrown, we rollback the transaction to restore the database to its previous state. Package Library: This method is supported by most relational database systems and can be used with various PHP database libraries such as PDO, MySQL, and SQLite.