Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery-terminal/examples/mysql-rpc-demo.php
1293 views
1
<?php
2
3
require('json-rpc.php');
4
5
if (function_exists('xdebug_disable')) {
6
xdebug_disable();
7
}
8
9
10
11
class MysqlDemo {
12
public function query($query) {
13
$link = new mysqli('localhost', 'user', 'password', 'db_name');
14
if (mysqli_connect_errno()) {
15
throw new Exception("MySQL Connection: " . mysqli_connect_error());
16
}
17
if (preg_match("/create|drop/", $query)) {
18
throw new Exception("Sorry you are not allowed to execute '" .
19
$query . "'");
20
}
21
if (!preg_match("/^\s*(select.*from *test|insert *into *test.*|delete *from *test|update *test)\s*$/", $query)) {
22
throw new Exception("Sorry you can't execute '" . $query .
23
"' you are only allowed to select, insert, delete " .
24
"or update 'test' table");
25
}
26
if ($res = $link->query($query)) {
27
if ($res === true) {
28
return true;
29
}
30
if ($res->num_rows > 0) {
31
while ($row = $res->fetch_array(MYSQLI_NUM)) {
32
$result[] = $row;
33
}
34
return $result;
35
} else {
36
return array();
37
}
38
} else {
39
throw new Exception("MySQL Error: " . mysqli_error($link));
40
}
41
}
42
}
43
44
handle_json_rpc(new MysqlDemo());
45
46
?>
47
48