-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.php
57 lines (49 loc) · 1.49 KB
/
select.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
// json response array
$response = array("error" => FALSE);
if(isset($_POST["prep_query"]) && isset($_POST["param_type"]) && isset($_POST["params"]))
{
require_once "DB_Functions.php";
$db = new DB_Functions();
// Prepare statement
$stmt = $db->conn->prepare($_POST["prep_query"]);
$params = json_decode($_POST["params"]);
if(count($params))
$stmt->bind_param($_POST["param_type"], ...$params);
// Try to execute prepered statement
if ($stmt->execute())
{
$hasResult = $stmt->get_result();
if ($hasResult)
{
$result = $hasResult->fetch_all(MYSQLI_ASSOC);
}
else
{
$result = true;
$response["id"] = $db->conn->insert_id;
}
$stmt->close();
if($result)
{
$response["result"] = $result;
}
else
{
$response["error"] = true;
$response["error_msg"] = "Nessun record corrisponde ai criteri di ricerca";
}
}
else
{
$response["error"] = true;
$response["error_msg"] = "Si è verificato un errore imprevisto, riprova.";
}
}
else
{
$response["error"] = true;
$response["error_msg"] = "I parametri richiesti sono obbligatori";
}
echo json_encode($response);
?>