diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2017-08-29 23:06:46 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2017-08-29 23:16:41 +0200 |
commit | d0074cf0069322fe175fb385b91c974fc2771547 (patch) | |
tree | 713fcb1f426c8a693938e3c8bbfc685e57f79e69 /src/Database/Db.php | |
parent | 50da458d8907cc7c05938565faa80b271bbf9b3d (diff) | |
parent | 581b81f1b25dc6b6f0a3b34810c293738fd40217 (diff) |
Merge remote-tracking branch 'engelsystem/feature-igel-rewrite'
# Conflicts:
# includes/controller/angeltypes_controller.php
# includes/pages/admin_groups.php
# includes/pages/user_settings.php
# includes/sys_page.php
# src/Exceptions/Handler.php
# src/Http/Request.php
Diffstat (limited to 'src/Database/Db.php')
-rw-r--r-- | src/Database/Db.php | 29 |
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(); } /** |