Only the MySQL storage engine InnoDB supports transactions. A major benefit of transactions is that it’s possible to roll back changes until a transaction is committed. This example show you how to write multi-statement transaction, how to perform a rollback in case of errors and how to commit a transaction.
In autocommit mode (the InnoDB default behavior), MySQL does a commit after each SQL statement that was executed without errors. That makes it impossible to roll back an committed statement. When we start a new transaction, the autocommit mode is disabled implicitly by MySQL and enabled again once we commit the transaction:
START TRANSACTION; -- ... -- add all insert & update statements here -- to save the received order -- ... -- on success: COMMIT; -- in case of failure:[Read more...]