-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.php
More file actions
93 lines (73 loc) · 2 KB
/
index2.php
File metadata and controls
93 lines (73 loc) · 2 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$servername = "localhost";
$username = "root";
if ($_SERVER["SERVER_NAME"] == "test.loc") {
$password = "";
$dbname = "gis_ktga";
} else {
$password = "aidos123";
$dbname = "test";
}
// // Create connection
// $conn = new mysqli($servername, $username, $password, $dbname);
// // Check connection
// if ($conn->connect_error) {
// die("Connection failed: " . $conn->connect_error);
// }
mysql_connect('localhost','root','aidos123') or die("Not connect to MySQL");
mysql_select_db('test') or die("Not connect to DB");
mysql_set_charset('utf8');
header('Content-Type: application/json');
class SQL {
public function getOne($sql){
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
return $row;
}
public function execute($sql){
$sql = mysql_query($sql);
while ($row = mysql_fetch_assoc($sql)) {
$data[] = $row;
}
return $data;
}
public function getOneWithCache($sql){
$Memcache = new Memcache();
$Memcache->connect('localhost', 11211) or die ("Не могу подключиться");
$res = $Memcache->get(md5($sql));
if($res){
$data=$res;
}else{
$sql = @mysql_query($sql);
$data = @mysql_fetch_assoc($sql);
$Memcache->set(md5($sql),$data,100);
}
return $data ;
}
public function executeWithCache($sql){
$Memcache = new Memcache();
$Memcache->connect('localhost', 11211) or die ("Не могу подключиться");
$res = $Memcache->get(md5($sql));
if($res){
$data=$res;
}else{
$sql = @mysql_query($sql);
while ($row = @mysql_fetch_assoc($sql)) {
$data[] = $row;
}
$Memcache->set(md5($sql),$data,100);
}
return $data;
}
}
if (isset($_GET['street']) && isset($_GET['housenum'])) {
$street = $_GET['street'];
$housenum = $_GET['housenum'];
$sql = "SELECT account FROM `abonents` WHERE `street` LIKE '%".$street."%' AND `housenum` = '".$housenum."'";
$data['response'] = json_encode(SQL::execute($sql));
} else {
$data['response'] = "No query params!!!";
}
//var_dump($sql);
var_dump($data);
?>