summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Database/Db.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Database/Db.php b/src/Database/Db.php
index b433f40d..9422ae77 100644
--- a/src/Database/Db.php
+++ b/src/Database/Db.php
@@ -79,6 +79,23 @@ class Db
return self::$stm->fetchAll(PDO::FETCH_ASSOC);
}
+
+ /**
+ * Run a select query and return only the first result or null if no result is found.
+ * @param string $query
+ * @param array $bindings
+ * @return array|null
+ */
+ public static function selectOne($query, array $bindings = [])
+ {
+ $result = self::select($query);
+
+ if(empty($result)) {
+ return null;
+ }
+
+ return array_shift($result);
+ }
/**
* Run an insert query