transactions - Automocity in PHP (Begin and Commit in PHP) -


may sound silly, want know there way enclose php codes in functions if error happen rollback process has done.? (like done in mysql- automocity) ex :

$this->begin; $this->function1(); $this->function2(); $this->commit; 

a database server can rollback changes database table, since php far more powerful, cannot done (easily).

you this:

try {     // / create file     file_put_contents("/tmp/test.txt", "test");      // ... more actions here ...      // error occurs, rollback!     if($some_error)     {         throw new exception();     } } catch(exception $e) {     // undo changes     @unlink("/tmp/test.txt"); } 

also note there few things cannot undone. http call webservice example.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -