Hello,
Say I have a function with 5 MySQL queries that all insert or update the
database. Now let's assume that during execution, the first 3 queries
are executed fine but then the 4th one dies for some reason - problem
with the database, connection, whatever.
Obviously I can test the $result variable to see if it returns true or
false, but given the case above, the database is now left in a "corrupt"
state (assuming all 5 queries have to succeed in order for the database
to be correct).
So, if I receive false for any of the results, is there an efficient way
to "roll-back" the database to its original state? Specifically in the
above example, is there a way to undo the first 3 queries?
I thought of setting flags in an array so that, for example, if query 4
dies, I can automatically undo queries 1 through 3 with new queries that
would return the database to its original form, but if there is a
problem that prevented query 4 from executing, I don't see how I can
guarantee that I would be able to successfully execute new queries to
undo the first 3.
Thanks in advance.
Say I have a function with 5 MySQL queries that all insert or update the
database. Now let's assume that during execution, the first 3 queries
are executed fine but then the 4th one dies for some reason - problem
with the database, connection, whatever.
Obviously I can test the $result variable to see if it returns true or
false, but given the case above, the database is now left in a "corrupt"
state (assuming all 5 queries have to succeed in order for the database
to be correct).
So, if I receive false for any of the results, is there an efficient way
to "roll-back" the database to its original state? Specifically in the
above example, is there a way to undo the first 3 queries?
I thought of setting flags in an array so that, for example, if query 4
dies, I can automatically undo queries 1 through 3 with new queries that
would return the database to its original form, but if there is a
problem that prevented query 4 from executing, I don't see how I can
guarantee that I would be able to successfully execute new queries to
undo the first 3.
Thanks in advance.
Comment