Transactions - Life Preservers
Text Book:
- system crash between one bank account being debited and another being credited.
Dramatic:
- power failure during update on 3 million rows when only part way through.
Real-world:
- complex series of inter-related updates, deletes and inserts on many separate tables fails at the last step due to a duplicate unique key on an insert.
-
Locking alone won’t help you in any of these situations
- (And locking with DBD::mysql < 2.1027 is unsafe due to auto reconnect)
Transaction recovery would handle all these situations - automatically
- Makes a system far more robust and trustworthy over the long term.
Use transactions if your database supports them.
- If it doesn't and you need them, switch to a different database.