I havn’t been able to find an answer to this, and it may very well be because it has a name i don’t know. Anywho.
If you have multiple operations on a database, e.g:
if(insert_something_to_db($data) == TRUE){
if(delete_something_else_from_db($data2) == TRUE){
if(update_something_related_to_the_others_in_db($data3) == TRUE){
return TRUE;
}
}
} else {
return FALSE;
}
If any of the nested queries fails, then the previous operations will have been concluded, which results in messy data in the database. Is it possible/is there some technique/best practice, to halt the execution of the operations, until you know if they all will be successful.
I have an example:
If a person wants to join a group, he clicks ‘Join Group’
– A notification is created in the db. This show up in the administration panel of the group owner.
– The group owner can reject/accept the application.
On Accept:
– Applicant user data is updated with the new group information.
– The Notification originally sent to the group administrator is going to be deleted
– A new notification is created for the applicant, to inform him he was accepted.
It is only if the outer most condition returns false (lets say user data updated), the actual db is holding the original data. If the first update goes through, but not the next, then the profile was updated to reflect the link with the new group, but the notification in the group administrators area is not gone.
Regards
Dennis
You want all your queries to be in a transaction, to ensure an all-or-nothing behavior.
Basically, you will :
You might want to read, for more general informations : Database transaction