forked from soapdog/livecode-dblib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdblibserver.php
More file actions
63 lines (46 loc) · 1.3 KB
/
Copy pathdblibserver.php
File metadata and controls
63 lines (46 loc) · 1.3 KB
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
<?php
/*
Remote DB Lib Server
*/
// Override the data below with your defaults
$encryption_password = "";
$user = "";
$password = "";
$db = "";
$server = "localhost";
// decrypt the post
$post = $_POST_RAW;
$post = openssl_decrypt($post, "aes-256-ctr", $encryption_password);
$req = json_decode($post, true);
if (isset($req["user"])) {
$user = $req["user"];
}
if (isset($req["password"])) {
$password = $req["password"];
}
if (isset($req["db"])) {
$db = $req["db"];
}
$type = $req["type"];
$retVal = [];
$mysqli = new mysqli($server, $user, $password, $db);
if (mysqli_connect_errno()) {
$retVal["error"] = mysqli_connect_error();
} else {
switch($type) {
case "execute":
$query = $mysqli->query($sql);
$retVal["affected_rows"] = $query->affected_rows;
break;
case "query":
$query = $mysqli->query($sql);
$data = $query->mysqli_fetch_array();
$retVal["data"] = $data;
$retVal["num_rows"] = $query->num_rows;
break;
}
}
header('Content-Type: text/plain');
$retVal = openssl_decrypt(json_encode($retVal), "aes-256-ctr", $encryption_password);
echo $retVal;
// encrypt the result