Skip to content

Instantly share code, notes, and snippets.

@dusta
Created September 18, 2018 13:11
Show Gist options
  • Save dusta/9187cf33cf092633f448307e6fa73eeb to your computer and use it in GitHub Desktop.
Save dusta/9187cf33cf092633f448307e6fa73eeb to your computer and use it in GitHub Desktop.
Safe multi Transaction Dframe\Database
<?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