-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.php
More file actions
92 lines (76 loc) · 2.33 KB
/
book.php
File metadata and controls
92 lines (76 loc) · 2.33 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
<?php
/**
* Created by PhpStorm.
* User: longer
* Date: 2017/5/30
* Time: 17:33
*/
include './utils.php';
$mysql_con = new mysqli('localhost:3306','root','1994woaini');
if(!$mysql_con){
die(toJsonString(-3,"服务器出错",array()));
}
$mysql_con->query("set names 'utf8'");
if(!$mysql_con->query("use yuewen")){
die(toJsonString(-8,"服务器出错",array()));
}
if(!isset($_POST['method'])){
die(toJsonString(-10,"未知方法名"));
}
switch ($_POST['method'])
{
case 'addbook':
addbook();
break;
case 'getbooklist':
getBookList();
break;
default:
die(toJsonString(-10,"未知方法名"));
break;
}
function addbook(){
global $mysql_con;
$time = time();
$uid = isset($_POST['uid'])?$_POST['uid']:false;
$bname = isset($_POST['bname'])?$_POST['bname']:false;
$bauthor = isset($_POST['bauthor'])?$_POST['bauthor']:false;
$brepublic = isset($_POST['brepublic'])?$_POST['brepublic']:false;
$bdesc = isset($_POST['bdesc'])?$_POST['bdesc']:null;
$bimage = isset($_POST['bimage'])?$_POST['bimage']:null;
if(!$uid||!$bname||!$bauthor||!$brepublic){
die(toJsonString(-10,"缺少必须的字段"));
}
$query_addbook = "insert into book (uid,bname,bauthor,brepublic,bdesc,images,btime)
VALUE ('$uid','$bname','$bauthor','$brepublic','$bdesc','$bimage','$time')";
$result = $mysql_con->query($query_addbook);
if(!$result){
die(toJsonString(-1,"上传失败"));
}
die(toJsonString(0,"上传成功"));
}
function getBookList(){
$query_statment = "select u.uname,u.uicon,b.*
from book b
INNER JOIN userinfo u
on b.uid = u.uid LIMIT 20";
global $mysql_con;
$uid = isset($_POST['uid'])?$_POST['uid']:false;
if($uid){
$query_statment = "select u.uname,u.uicon,b.*
from book b
INNER JOIN userinfo u
on b.uid = u.uid and u.uid = '$uid' LIMIT 20";
}
$result = $mysql_con->query($query_statment);
$data = array();
if(!$result){
die(toJsonString(-2,'查询失败'));
}
while(($data_fetch=$result->fetch_assoc())!=null){
$data[] = $data_fetch;
}
echo toJsonString(0,'查询成功',$data);
mysqli_free_result($data);
}
?>