T201704031100

This commit is contained in:
Leander
2017-04-03 11:01:03 +02:00
parent a2754912b3
commit dea40f389a
2 changed files with 4 additions and 6 deletions

View File

@@ -21,12 +21,12 @@ class Database
function query($sql, $params = null) { function query($sql, $params = null) {
$result = null; $result = null;
$error = 0; $error = 0;
if($params) { if(isset($params)) {
$result = pg_query_params($this->db, $sql, $params); $result = pg_query_params($this->db, $sql, $params);
} else { } else {
$result = pg_query($this->db, $sql); $result = pg_query($this->db, $sql);
} }
if(!$result) { if(!isset($result)) {
$error = 10101; $error = 10101;
} }
if($error == 0) { if($error == 0) {

View File

@@ -34,9 +34,7 @@
$values = array($questions_count); $values = array($questions_count);
} else { } else {
// Delete existing game for user. // Delete existing game for user.
$exists = ($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)))['data'][0]['exists']; if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid))['data'][0]['exists'] == 't') {
print_r($exists);
if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)) == 't') {
$db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid)); $db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid));
} }
// Create new game for user. // Create new game for user.
@@ -44,7 +42,7 @@
// Find questions for new game and insert into table. // Find questions for new game and insert into table.
$questions = random_numbers(0, $questions_count-1, $length); $questions = random_numbers(0, $questions_count-1, $length);
foreach($questions as $question) { 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)); $db->query('INSERT INTO "GamesQuestions" ("Games_ID", "Questions_ID") VALUES ($1, $2)', array($uid, $q));
} }
} }