I'm rewriting this question because it got no responses.
I'm trying to figure out the correct way to work with db transactions. Everything I see about how to do transactions is very basic, along the lines of:
- query "begin" to start transaction
- run your queries.
- if everything ran fine, commit transaction.
I get that, but it's error (deadlock) handling I don't get. I've heard of two options:
- Show the user an error and say "try again"
- Try again on the spot until it succeeds.
To me, telling the user to try again because of a technical issue like this seems bad - do real applications do this regularly? Is that the "oops, something went wrong" one-off errors I sometimes see? This is for a website, so users shouldn't even be aware of the database.
So I have a few questions:
- Which failure handling approach should I take with data involving multiple users at once?
- If I do the "instant retry" option, what does that entail for a complex PHP script? Restart the whole request from the top? I'm worried this will cause more problems than it solves.
- Is there a third option I haven't seen?