// Connect to the database using PDO $pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password'); // Begin a transaction $pdo->beginTransaction(); try { // Perform some database operations $pdo->exec("INSERT INTO mytable (name, email) VALUES ('John', 'john@example.com')"); $pdo->exec("UPDATE mytable SET email='john.doe@example.com' WHERE name='John'"); // Commit the transaction $pdo->commit(); echo 'Transaction succeeded'; } catch (PDOException $e) { // Roll back the transaction on error $pdo->rollBack(); echo 'Transaction failed: ' . $e->getMessage(); }In this example, we use the `beginTransaction`, `commit`, and `rollBack` methods of the PDO object to start, end, or rollback a transaction respectively. If any of the SQL statements inside the transaction block fail, the catch block is executed, and the transaction is rolled back using the `rollBack` method. PDO is a package library for PHP that provides a powerful, flexible, and easy-to-use interface to connect to databases such as MySQL, PostgreSQL, SQLite, and more. It offers many features, including prepared statements, transactions, error handling, and more, making it a popular choice for PHP developers when working with databases.