From 01842f99b65b06d2647470c3b867719e72dabde7 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Mon, 5 Oct 2020 21:44:27 +0200 Subject: Introduce some new database wrappers This will allow us to avoid using globals and use the autoloader in the future. --- ratatoeskr/sys/DbTransaction.php | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ratatoeskr/sys/DbTransaction.php (limited to 'ratatoeskr/sys/DbTransaction.php') diff --git a/ratatoeskr/sys/DbTransaction.php b/ratatoeskr/sys/DbTransaction.php new file mode 100644 index 0000000..ed1f9ac --- /dev/null +++ b/ratatoeskr/sys/DbTransaction.php @@ -0,0 +1,47 @@ +db = $db; + + $this->startedHere = !$this->db->getPdo()->inTransaction(); + if ($this->startedHere) { + $this->db->getPdo()->beginTransaction(); + } + } + + /** + * Commit the transaction. + */ + public function commit(): void + { + if ($this->startedHere) { + $this->db->getPdo()->commit(); + } + } + + /** + * Roll the transaction back. + */ + public function rollback(): void + { + if ($this->startedHere) { + $this->db->getPdo()->rollBack(); + } + } +} -- cgit v1.2.3-70-g09d2