From a6b5dd83c3b1b0b35cc13810cee99522271062d5 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Fri, 26 Apr 2024 16:08:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=81=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=B2?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D1=8B=20false=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=20=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B9=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _incl_data/class/Core/Db.php | 30 +++++++++++++++++++--------- _incl_data/class/User/Reputation.php | 20 +++++++++---------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/_incl_data/class/Core/Db.php b/_incl_data/class/Core/Db.php index 813a20bc..6413b42d 100644 --- a/_incl_data/class/Core/Db.php +++ b/_incl_data/class/Core/Db.php @@ -53,11 +53,15 @@ class Db /** * @param string $query * @param array $args - * @return false|array + * @return array */ - public static function getRows(string $query, array $args = []): false|array + public static function getRows(string $query, array $args = []): array { - return self::run($query, $args)->fetchAll(); + $stmt = self::run($query, $args)->fetchAll(); + if (!$stmt) { + return []; + } + return $stmt; } /** @@ -108,19 +112,23 @@ class Db { $result = self::getRow($query, $args); if (!empty($result)) { - $result = array_shift($result); + return array_shift($result); } - return $result; + return ''; } /** * @param string $query * @param array $args - * @return mixed + * @return array */ - public static function getRow(string $query, array $args = []): mixed + public static function getRow(string $query, array $args = []): array { - return self::run($query, $args)->fetch(); + $stmt = self::run($query, $args)->fetch(); + if (!$stmt) { + return []; + } + return $stmt; } /** @@ -130,7 +138,11 @@ class Db */ public static function getColumn(string $query, array $args = []): array { - return self::run($query, $args)->fetchAll(PDO::FETCH_COLUMN); + $stmt = self::run($query, $args)->fetchAll(PDO::FETCH_COLUMN); + if (!$stmt) { + return []; + } + return $stmt; } /** diff --git a/_incl_data/class/User/Reputation.php b/_incl_data/class/User/Reputation.php index 23e671bb..fd739db0 100644 --- a/_incl_data/class/User/Reputation.php +++ b/_incl_data/class/User/Reputation.php @@ -20,6 +20,16 @@ class Reputation } } + private function getr(): array + { + return Db::getRow( + 'select *, + (repcapitalcity+repdemonscity+repangelscity+repsuncity+repdreamscity+repabandonedplain+repsandcity+repemeraldscity+repdevilscity) as allrep, + (nu_capitalcity+nu_demonscity+nu_angelscity+nu_suncity+nu_dreamscity+nu_abandonedplain+nu_sandcity+nu_emeraldscity+nu_devilscity) as allnurep + from rep where id = ?', [$this->uid] + ); + } + public function get(): array { return $this->r; @@ -34,14 +44,4 @@ class Reputation Db::sql("update rep set $dungeonName = ? where id = ?", [$value, $this->uid]); return $this->r[$dungeonName]; } - - private function getr() - { - return Db::getRow( - 'select *, - (repcapitalcity+repdemonscity+repangelscity+repsuncity+repdreamscity+repabandonedplain+repsandcity+repemeraldscity+repdevilscity) as allrep, - (nu_capitalcity+nu_demonscity+nu_angelscity+nu_suncity+nu_dreamscity+nu_abandonedplain+nu_sandcity+nu_emeraldscity+nu_devilscity) as allnurep - from rep where id = ?', [$this->uid] - ); - } } \ No newline at end of file