blob: 06caa8696608a79c2ca072193159d327e11bb744 (
plain) (
blame)
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
|
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$req = json_decode(file_get_contents("php://input"));
require_once "../../backend/dbCredentials.php";
if ($req->apiKey === $apiKey) {
$http = isset($_SERVER["HTTPS"]) ? "https" : "http";
header("Access-Control-Allow-Origin: $http://localhost:8000");
$pdo = new PDO("mysql:dbname=$dbName;host=localhost;charset=utf8mb4", $dbUser, $dbPassword);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $pdo->prepare($req->query);
try {
$params = [];
foreach ($req->params as $v) {
if(is_string($v))
array_push($params, $v);
else
array_push($params, json_encode($v));
}
$stmt->execute($params);
} catch (PDOException $e) {
echo "ERROR!!!";
var_dump($req);
var_dump($stmt);
throw $e;
}
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
http_response_code(200);
} else {
echo "Wrong username or password!";
http_response_code(401);
}
|