-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_questions.php
More file actions
39 lines (29 loc) · 859 Bytes
/
Copy pathfetch_questions.php
File metadata and controls
39 lines (29 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";
use PhotoTech\ErrorHandler;
use PhotoTech\Database;
use PhotoTech\TriviaDatabaseOBJ as Trivia;
$errorHandler = new ErrorHandler();
// Register the exception handler method
set_exception_handler([$errorHandler, 'handleException']);
$database = new Database();
$pdo = $database->createPDO();
$trivia = new Trivia($pdo);
$category = htmlspecialchars($_GET['category']);
$data = $trivia->fetchQuestions($category);
// Save data to JSON file
file_put_contents('output.json', json_encode($data));
output($data);
/*
* After converting data array to JSON send back to javascript using
* this function.
*/
function output($output): void
{
http_response_code(200);
try {
echo json_encode($output, JSON_THROW_ON_ERROR);
} catch (JsonException) {
}
}