Last active
December 25, 2015 10:29
-
-
Save Ikke/6962286 to your computer and use it in GitHub Desktop.
Transaction wrapper (pseudocode)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Transaction | |
{ | |
protected $db; | |
public function __construct($db) | |
{ | |
$this->db = $db | |
} | |
public function execute(Command $command) | |
{ | |
$this->db->start_transaction(); | |
try | |
{ | |
$command->execute(); | |
} | |
catch (Exception $ex) { //Catch an appropiate exception here | |
$this->db->roll_back(); | |
return; | |
} | |
$db->commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment