Created
September 18, 2018 13:11
-
-
Save dusta/9187cf33cf092633f448307e6fa73eeb to your computer and use it in GitHub Desktop.
Safe multi Transaction Dframe\Database
This file contains 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 | |
namespace Model; | |
/** | |
* Class Database | |
* Klasa rozbudowuje transakcje o lvl | |
* | |
* @package Model | |
*/ | |
class Database extends \Dframe\Database\Database | |
{ | |
private $transactionCounter = 0; | |
public function start() | |
{ | |
if (!$this->transactionCounter++) { | |
return $this->beginTransaction(); | |
} | |
$this->exec('SAVEPOINT trans' . $this->transactionCounter); | |
return $this->transactionCounter >= 0; | |
} | |
/** | |
* Start PDO Commit. | |
*/ | |
public function end() | |
{ | |
if (!--$this->transactionCounter) { | |
return $this->commit(); | |
} | |
return $this->transactionCounter >= 0; | |
} | |
/** | |
* Start PDO Rollback. | |
*/ | |
public function back() | |
{ | |
if (--$this->transactionCounter) { | |
$this->exec('ROLLBACK TO trans' . ++$this->transactionCounter); | |
return true; | |
} | |
// roll back the transaction if we fail | |
$this->rollback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment