summaryrefslogtreecommitdiff
path: root/src/Database
diff options
context:
space:
mode:
Diffstat (limited to 'src/Database')
-rw-r--r--src/Database/Db.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/Database/Db.php b/src/Database/Db.php
index 4116ffda..777b16a2 100644
--- a/src/Database/Db.php
+++ b/src/Database/Db.php
@@ -79,19 +79,36 @@ 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, $bindings);
+
+ if(empty($result)) {
+ return null;
+ }
+
+ return array_shift($result);
+ }
/**
* Run an insert query
*
* @param string $query
* @param array $bindings
- * @return int|bool
+ * @return int Row count
*/
public static function insert($query, array $bindings = [])
{
self::query($query, $bindings);
- return (self::$lastStatus ? self::$stm->rowCount() : false);
+ return self::$stm->rowCount();
}
/**
@@ -99,13 +116,13 @@ class Db
*
* @param string $query
* @param array $bindings
- * @return int|bool
+ * @return int
*/
public static function update($query, array $bindings = [])
{
self::query($query, $bindings);
- return (self::$lastStatus ? self::$stm->rowCount() : false);
+ return self::$stm->rowCount();
}
/**
@@ -113,13 +130,13 @@ class Db
*
* @param string $query
* @param array $bindings
- * @return int|bool
+ * @return int
*/
public static function delete($query, array $bindings = [])
{
self::query($query, $bindings);
- return (self::$lastStatus ? self::$stm->rowCount() : false);
+ return self::$stm->rowCount();
}
/**