From 464a9c7dbce63ff46c797d7585971dada80d9767 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Thu, 19 Jan 2023 18:37:48 +0100 Subject: [PATCH] fix: select fetchAll --- BancaDati/BancaDati.php | 7 ++++--- User.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 9690979..c678d7a 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -22,6 +22,7 @@ class BancaDati { , $this->pw , array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (PDOException $e) { + var_dump($e); die; } } @@ -108,7 +109,7 @@ class BancaDati { * @return void * @author Malte Schulze Hobeling */ - public function select(string $table, array $where){ + public function select(string $table, array $where = []){ $whereString = ""; $orderString = ""; if(isset($where["by"])){ @@ -125,9 +126,9 @@ class BancaDati { } $whereString .= "`" . $col . "` LIKE '" . $v . "'"; } - $sql = "SELECT * FROM ".$table." WHERE ".$whereString.$orderString.";"; + $sql = "SELECT * FROM " . $table . ((count($where) > 0) ? " WHERE ".$whereString.$orderString : "") .";"; try { - return $this->pdo->query($sql)->fetch(); + return $this->pdo->query($sql)->fetchAll(); }catch (PDOException $e){ die; } diff --git a/User.php b/User.php index 203368b..ba73a67 100644 --- a/User.php +++ b/User.php @@ -18,7 +18,7 @@ class User { return true; } public function loginWithUsername(string $username, string $password) : string { - $userObject = $this->db->select("utente", ["nomeUtente" => $username]); + $userObject = $this->db->select("utente", ["nomeUtente" => $username])[0]; if(!$userObject){ return false; @@ -38,7 +38,7 @@ class User { return $this->token; } public function loginWithToken(string $token){ - $userObject = $this->db->select("utente", ["gettone" => $token]); + $userObject = $this->db->select("utente", ["gettone" => $token])[0]; if(!$userObject){ return false; }