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:
$db->beginTransaction(); $update = $db->prepare("UPDATE `table` SET `col` = 1 WHERE `col2` = ?"); $update->execute([$value]);
Rollback on the query can now be done with:
$db->rollBack();
This will return the database back to its state pre query.