|
|
@@ -0,0 +1,31 @@
|
|
|
+<?php
|
|
|
+ error_reporting( E_ALL );
|
|
|
+ $hostname = 'localhost';
|
|
|
+ $username = 'narKampen';
|
|
|
+ $pass = 'narKampenPassword';
|
|
|
+ $database = 'narKampen';
|
|
|
+
|
|
|
+ $conn = new mysqli($hostname, $username, $pass, $database);
|
|
|
+
|
|
|
+ if (!$conn) {
|
|
|
+ die("Connection Failed. ". mysqli_connect_error());
|
|
|
+ }
|
|
|
+ mysqli_set_charset($conn,'utf8');
|
|
|
+
|
|
|
+ $sql = 'SELECT * FROM questions ORDER BY RAND() limit 1';
|
|
|
+ $result = mysqli_query($conn, $sql);
|
|
|
+
|
|
|
+ $json = array();
|
|
|
+
|
|
|
+ if (mysqli_num_rows($result) > 0) {
|
|
|
+ while ($row = mysqli_fetch_assoc($result)) {
|
|
|
+ $json = array('id' => $row['id'],
|
|
|
+ 'question' => $row['question'],
|
|
|
+ 'answer' => $row['answer'],
|
|
|
+ 'category' => $row['category']);
|
|
|
+ }
|
|
|
+ $jsonString = json_encode($json);
|
|
|
+ echo $jsonString;
|
|
|
+ }
|
|
|
+
|
|
|
+?>
|