From cc7cd638e38554a192d366a4a93123105a9678d5 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 12 Sep 2022 21:54:20 -0300 Subject: [PATCH] Added check for empty or false results. --- src/Database/ResultSet.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Database/ResultSet.php b/src/Database/ResultSet.php index 71c3517..dfe9aed 100644 --- a/src/Database/ResultSet.php +++ b/src/Database/ResultSet.php @@ -31,18 +31,34 @@ class ResultSet implements RSInterface public function getAsArray(): array { - return $this->getStatement()->fetchAll(PDO::FETCH_ASSOC); + $rs = $this->getStatement()->fetchAll(PDO::FETCH_ASSOC); + if (!$rs) { + throw new \PDOException("No results found."); + } + return $rs; } public function getAsObject(): array { - return $this->getStatement()->fetchAll(PDO::FETCH_OBJ); + $rs = $this->getStatement()->fetchAll(PDO::FETCH_OBJ); + if (!$rs) { + throw new \PDOException("No results found."); + } + return $rs; } public function getFirstAsArray(): array { - return $this->getStatement()->fetch(PDO::FETCH_ASSOC); + $rs = $this->getStatement()->fetch(PDO::FETCH_ASSOC); + if (!$rs or count($rs) === 0) { + throw new \PDOException("No results found."); + } + return $rs; } public function getFirstAsObject(): object { - return $this->getStatement()->fetch(PDO::FETCH_OBJ); + $rs = $this->getStatement()->fetch(PDO::FETCH_OBJ); + if (!$rs or count($rs) === 0) { + throw new \PDOException("No results found."); + } + return $rs; } }