forked from alixaxel/ArrestDB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharrestDBdirect.php
74 lines (61 loc) · 1.44 KB
/
arrestDBdirect.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
session_start();
require('security.php');
require ('Call_ArrestDB.php');
if(!isset($_SESSION['user'])){
// if not logged exits
// except if caller is local
$ok = false;
if(isset($_SERVER['REMOTE_ADDR']) &&
(($_SERVER['REMOTE_ADDR']=='::1')||($_SERVER['REMOTE_ADDR']=='127.0.0.1'))){
$ok=true;
}
if (!$ok){
exit(ArrestDB::Reply(ArrestDB::$HTTP[302]));
}
}
$dsn = 'sqlite://C:/inetpub/wwwroot/ArrestDB/Northwind.sqlite';
$clients = [];
if (ArrestDB::Query($dsn) === false)
{
exit(ArrestDB::Reply(ArrestDB::$HTTP[503]));
}
$json = file_get_contents('php://input');
if ((!isset($json))|| is_null($json) ){
$result = ArrestDB::$HTTP[204];
exit(ArrestDB::Reply($result));
}
$query = json_decode($json);
if ((!isset($query))|| is_null($query) || ($query=="") ){
$result = ArrestDB::$HTTP[204];
exit(ArrestDB::Reply($result));
}
$result = ArrestDB::Query($query);
if ($result === false)
{
$result = ArrestDB::$HTTP[404];
}
else if (empty($result) === true)
{
$result = ArrestDB::$HTTP[204];
}
$count = count($result);
if ($count==1){
if(!isset($result['error'])){
$colcount = count($result[0]);
if($colcount==1){
foreach($result[0] as $key => $value){
echo $value;
}
} else {
echo ArrestDB::Reply($result);
}
} else {
echo ArrestDB::Reply($result);
}
} else if($count>1){
echo ArrestDB::Reply($result);
} else {
echo "{}";
}
?>