35 lines
803 B
PHP
35 lines
803 B
PHP
<?php
|
|
|
|
namespace Ulmus\Common\PdoObject;
|
|
|
|
class SqlPdoObject extends \Ulmus\Common\PdoObject
|
|
{
|
|
protected int $openedTransaction = 0;
|
|
|
|
public function beginTransaction(): bool
|
|
{
|
|
if ( 0 === ++$this->openedTransaction ) {
|
|
return parent::beginTransaction();
|
|
}
|
|
|
|
return $this->exec('SAVEPOINT transaction_'.$this->openedTransaction) !== false;
|
|
}
|
|
|
|
public function commit() : bool
|
|
{
|
|
if ( 0 === --$this->openedTransaction) {
|
|
return parent::commit();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function rollback() : bool
|
|
{
|
|
if (0 !== $this->openedTransaction) {
|
|
return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false;
|
|
}
|
|
|
|
return parent::rollback();
|
|
}
|
|
} |