MySQL rollback with PHP PDO

Roll back a MySQL transaction with the PDO rollBack() function.

All that is needed is beginTransaction.

Start a transaction and run a query that modifies a table:


$update = $db->prepare("UPDATE `table` SET `col` = 1 WHERE `col2` = ?");

Rollback on the query can now be done with:


This will return the database back to its state pre query.