-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaststone.php
161 lines (140 loc) · 3.97 KB
/
laststone.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html>
<body>
<?php
$a = @$_GET['a'] ? $_GET['a'] : '';
$uid = @$_GET['uid'] ? $_GET['uid'] : 0;
if (empty($a)) {
$output = array('data'=>NULL, 'info'=>'No parameters', 'code'=>-201);
exit(json_encode($output));
}
//走接口
if ($a == 'get_users') {
//检查用户
if ($uid == 0) {
$output = array('data'=>NULL, 'info'=>'The uid is null!', 'code'=>-401);
exit(json_encode($output));
}
//假设 $mysql 是数据库
$mysql = array(
10001 => array(
'uid'=>10001,
'vip'=>5,
'nickname' => 'Shine X',
'email'=>'[email protected]',
'qq'=>979137,
'gold'=>1500,
'powerplay'=> array('2xp'=>12,'gem'=>12,'bingo'=>5,'keys'=>5,'chest'=>8),
'gems'=> array('red'=>13,'green'=>3,'blue'=>8,'yellow'=>17),
'ctime'=>1376523234,
'lastLogin'=>1377123144,
'level'=>19,
'exp'=>16758,
),
10002 => array(
'uid'=>10002,
'vip'=>50,
'nickname' => 'elva',
'email'=>'[email protected]',
'qq'=>NULL,
'gold'=>14320,
'powerplay'=> array('2xp'=>1,'gem'=>120,'bingo'=>51,'keys'=>5,'chest'=>8),
'gems'=> array('red'=>13,'green'=>3,'blue'=>8,'yellow'=>17),
'ctime'=>1376523234,
'lastLogin'=>1377123144,
'level'=>112,
'exp'=>167588,
),
10003 => array(
'uid' => 10003,
'vip' => 5,
'nickname' => 'Lily',
'email' => '[email protected]',
'qq' => NULL,
'gold' => 1541,
'powerplay'=> array('2xp'=>2,'gem'=>112,'bingo'=>4,'keys'=>7,'chest'=>8),
'gems' => array('red'=>13,'green'=>3,'blue'=>9,'yellow'=>7),
'ctime' => 1376523234,
'lastLogin'=> 1377123144,
'level' => 10,
'exp' => 1758,
),
);
$uidArr = array(10001,10002,10003);
if (in_array($uid, $uidArr, true)) {
$output = array('data' => NULL, 'info'=>'The user does not exist!', 'code' => -402);
exit(json_encode($output));
}
//查询数据库
$userInfo = $mysql[$uid];
//输出数据
$output = array(
'data' => array(
'userInfo' => $userInfo,
'isLogin' => true,//是否首次登陆
'unread' => 4,//未读消息数量
'untask' => 3,//未完成任务
),
'info' => 'Here is the message which, commonly used in popup window', //消息提示,客户端常会用此作为给弹窗信息。
'code' => 200, //成功与失败的代码,一般都是正数或者负数
);
exit(json_encode($output));
} elseif ($a == 'get_games_result') {
//...
die('您正在调 get_games_result 接口!');
} elseif ($a == 'upload_avatars') {
//....
die('您正在调 upload_avatars 接口!');
}
?>
/*
<?php
echo "Connect to server...</br>";
//$con = mysql_connect("127.0.0.1:3306");
$con = mysql_connect("127.0.0.1:3306","root","mysql");
if(!$con){
die('Could not connect to DB: '.mysql_error());
}
echo "Server Connected!</br>";
echo "Create DB and if exists, echo msg</br>";
$sql = "CREATE DATABASE laststone";
if(mysql_query($sql, $con)){
echo "DB created!";
}else{
echo "Failed to create DB: " . mysql_error() . "</br>";
}
echo "Select DB and create table...</br>";
mysql_select_db("laststone",$con);
$sql = "CREATE TABLE user
(
uid int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(uid),
name varchar(15),
age int
)";
mysql_query($sql,$con);
echo "Insert values to table...</br>";
$sql = "INSERT INTO user (name, age) VALUES ('atleast','31'),('atlast','100')";
mysql_query($sql);
echo "Select data from table....</br>";
$sql = "SELECT * FROM user WHERE name like 'at%' ORDER BY age DESC";
$result = mysql_query($sql);
echo "Display search result...</br>";
echo "<table border ='1'>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo "</table></br>";
echo "Close server connection.";
mysql_close($con);
?>
*/
</body>
</html>