try { $pdo->beginTransaction(); $pdo->exec("INSERT INTO accounts (id, name, balance) VALUES (1, 'Alice', 1000)"); $pdo->exec("INSERT INTO accounts (id, name, balance) VALUES (2, 'Bob', 2000)"); $pdo->exec("INSERT INTO accounts (id, name, balance) VALUES (3, 'Charlie', 3000)"); $pdo->commit(); } catch (PDOException $ex) { $pdo->rollBack(); echo "Error: " . $ex->getMessage(); }
try { $pdo->beginTransaction(); $stmt = $pdo->prepare("UPDATE employees SET salary = salary + 500 WHERE id = ?"); $stmt->execute([1]); // ... $pdo->rollBack(); } catch (PDOException $ex) { echo "Error: " . $ex->getMessage(); }In this example, we update a single row in the `employees` table and then call the rollBack() method to undo the update operation. Package Library: The PDO extension is included in PHP's core libraries, so there is no need to download any external package or library.