From 6947b726f02ab4e9ff5f80d232321265ca8cb28d Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Mon, 2 Mar 2020 15:21:49 +0000 Subject: [PATCH] Added exists function to database object --- core/database.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/database.php b/core/database.php index f06badd8..4f6643a0 100644 --- a/core/database.php +++ b/core/database.php @@ -251,6 +251,20 @@ class Database return $row ? $row[0] : null; } + /** + * Execute an SQL query and returns a bool indicating if any data was returned + */ + public function exists(string $query, array $args = []): bool + { + $_start = microtime(true); + $row = $this->execute($query, $args)->fetch(); + $this->count_time("exists", $_start, $query, $args); + if ($row==null) { + return false; + } + return true; + } + /** * Get the ID of the last inserted row. */