openedTransaction > 0; } public function commit(): bool { if ( 0 === --$this->openedTransaction) { return $this->exec("COMMIT") !== false; } return $this->exec("RELEASE SAVEPOINT transaction_{$this->openedTransaction}") !== false; } public function rollback() : bool { if ($this->openedTransaction > 1) { return $this->exec('ROLLBACK TO transaction_' . $this->openedTransaction--) !== false; } elseif ($this->openedTransaction-- === 1) { # We must do it manually since opening a transaction manually stucks PDO into thinking we've got no transaction opened return $this->exec('ROLLBACK') !== false; } return false; } protected function openTransaction(): bool { return $this->exec("BEGIN IMMEDIATE TRANSACTION") !== false; } }