summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Database/Db.php29
-rw-r--r--src/Exceptions/Handler.php6
2 files changed, 26 insertions, 9 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();
}
/**
diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php
index 6e5b4749..c4fb639c 100644
--- a/src/Exceptions/Handler.php
+++ b/src/Exceptions/Handler.php
@@ -2,7 +2,7 @@
namespace Engelsystem\Exceptions;
-use Exception;
+use Throwable;
class Handler
{
@@ -40,9 +40,9 @@ class Handler
}
/**
- * @param Exception $e
+ * @param Throwable $e
*/
- public function exceptionHandler(Exception $e)
+ public function exceptionHandler(Throwable $e)
{
$this->handle(
'exception',