From dea40f389aea393210a4b92ee06ccbeb25fa6f6d Mon Sep 17 00:00:00 2001 From: Leander Date: Mon, 3 Apr 2017 11:01:03 +0200 Subject: [PATCH] T201704031100 --- Database.php | 4 ++-- start.php | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Database.php b/Database.php index 175de4e..02c3ba3 100644 --- a/Database.php +++ b/Database.php @@ -21,12 +21,12 @@ class Database function query($sql, $params = null) { $result = null; $error = 0; - if($params) { + if(isset($params)) { $result = pg_query_params($this->db, $sql, $params); } else { $result = pg_query($this->db, $sql); } - if(!$result) { + if(!isset($result)) { $error = 10101; } if($error == 0) { diff --git a/start.php b/start.php index ffc95f9..6710032 100644 --- a/start.php +++ b/start.php @@ -34,9 +34,7 @@ $values = array($questions_count); } else { // Delete existing game for user. - $exists = ($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)))['data'][0]['exists']; - print_r($exists); - if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)) == 't') { + if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid))['data'][0]['exists'] == 't') { $db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid)); } // Create new game for user. @@ -44,7 +42,7 @@ // Find questions for new game and insert into table. $questions = random_numbers(0, $questions_count-1, $length); foreach($questions as $question) { - $q = $db->query('SELECT "ID" FROM "Questions" OFFSET $1 LIMIT 1', array($question)); + $q = $db->query('SELECT "ID" FROM "Questions" OFFSET $1 LIMIT 1', array($question))['data'][0]['ID']; $db->query('INSERT INTO "GamesQuestions" ("Games_ID", "Questions_ID") VALUES ($1, $2)', array($uid, $q)); } }