-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
33 lines (27 loc) · 949 Bytes
/
index.php
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
<?php
// Search string - change this for testing
$searchquery = "Franc*";
// debug starttime logger
$start = microtime(true);
// Use asteriks syntax for like statement
$searchquery = str_replace('*', '%', $searchquery);
// open database connection and fetch results
$db = new PDO("sqlite:database.db");
$sth = $db->prepare("SELECT * FROM MOCK_DATA WHERE first_name LIKE ? OR last_name LIKE ? OR email LIKE ? OR gender LIKE ? OR ip_address LIKE ?");
$sth->execute([$searchquery,$searchquery,$searchquery,$searchquery,$searchquery]);
$result = $sth->fetchAll();
// calculate a random score for each result item
foreach($result as $key => $value){
$result[$key]["score"] = random_int(0,100);
}
// debug endtime logger
$end = microtime(true);
// convert the result to josn and show it
header('Content-Type: application/json');
$output = [
"time" => $end-$start,
"items" => sizeof($result),
"results" => $result
];
echo json_encode($output);
?>