From 9db5e9b2bd80ecdeac691ce3c61575eab9b8a24e Mon Sep 17 00:00:00 2001 From: Gregory Letellier Date: Mon, 6 Nov 2023 10:17:40 +0100 Subject: [PATCH] ajout des transactions --- src/Connection.php | 24 ++++++++++++++++++++++++ src/Model.php | 6 ++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 655cf40..434b91f 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -160,6 +160,30 @@ class Connection } } + public function beginTransaction(): bool + { + if ($this->pdo) { + return $this->pdo->beginTransaction(); + } + return false; + } + + public function commit(): bool + { + if ($this->pdo) { + return $this->pdo->commit(); + } + return false; + } + + public function rollback(): bool + { + if ($this->pdo) { + return $this->pdo->rollBack(); + } + return false; + } + public static function init($config, array $connections = ["default"]) { self::fillInstances($config, $connections); diff --git a/src/Model.php b/src/Model.php index 734f12e..c800bcf 100644 --- a/src/Model.php +++ b/src/Model.php @@ -71,8 +71,7 @@ class Model $res = false; $qb = $this->newQueryBuilder(); $find = $qb->find($key); - if($find!==null) - { + if ($find !== null) { $this->fillData($find->getValues()); $res = true; } @@ -139,6 +138,5 @@ class Model $table = strtolower($classNameWithoutNamespace); return $table; - } - + } }