T201704031100
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user