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 - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -