-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdao.php
More file actions
193 lines (157 loc) · 4.57 KB
/
Copy pathdao.php
File metadata and controls
193 lines (157 loc) · 4.57 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
ini_set('date.timezone', 'Asia/Shanghai');
function getServerInfo() {
$configary = parse_ini_file("config/mysql.ini");
return $configary;
}
function trim_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function addUser(User $user) {
$sql = "INSERT INTO `user` (`username`, `password`, `nicname`, `lastlogin`) VALUES ('" . $user->getUsername() . "', '" . $user->getPassword() . "', '" . $user->getNicname() . "', '" . date('Y-m-d G:i:s') . "')";
return querySql($sql);
}
function findUserByUsername($username) {
$sql = "select * from `user` where username='" . $username . "'";
return querySql($sql);
}
function checkLogin($username,$password){
$res= findUserByUsername($username);
if(mysql_num_rows($res)==0){
return false;
}
else{
$user=mysql_fetch_array($res);
if($user["password"]== $password){
return true;
}
else{
return false;
}
}
}
function findExerciseTypes(){
$sql="select * from exercisetype";
$res= querySql($sql);
$array=array();
if($res){
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
$array[$row["id"]]=$row;
}
}
return $array;
}
function findExerciseTypeById($typeid){
$typeid= trim_input($typeid);
$sql="select * from exercisetype where id=".$typeid;
$res= querySql($sql);
if($res){
return mysql_fetch_array($res,MYSQL_ASSOC);
}
return null;
}
function addExercieRecord($typeid,$count,$totaltime,$date,$comment,$userid){
$uid= intval($userid);
$type= findExerciseTypeById($typeid);
$sql="INSERT INTO `exercise_record` (`userid`,`type`, `count`, `unit`, `totaltime`, `date`,`comment`) VALUES (".$uid.",'".$type["typename"]."',".$count.",'".$type["unit"]."', '".$totaltime."', '".$date."','".$comment."')";
$res= querySql($sql);
return $res;
}
/*添加健身计划*/
function addExecisePlan($userid,$title,$content){
$status=0;//初始化为未完成状态
$addtime=date("Y-m-d h:i:s");
$sql="INSERT INTO `exercise_plan` (`userid`, `title`, `content`, `addtime`, `status`) VALUES (".$userid.",'".$title."','".$content."', '".$addtime."', ".$status.")";
$res= querySql($sql);
return $res;
}
/*删除健身计划*/
function delExercisePlan($planid){
$id= intval($planid);
$sql="delete from `exercise_plan` where id=".$id;
$res= querySql($sql);
return $res;
}
/*查询健身记录*/
function queryAllExerciseData($userid){
$uid= intval($userid);
$sql="select * from `exercise_record` where userid=".$uid;
$ary=array();
$res= querySql($sql);
if($res){
while($row=mysql_fetch_array($res,MYSQL_ASSOC)){
array_push($ary, $row);
}
}
return $ary;
}
/*查询所有健身计划*/
function queryAllExercisePlan($userid){
$uid= intval($userid);
$sql="select * from `exercise_plan` where userid=".$uid;
$ary=array();
$res= querySql($sql);
if($res){
while($row=mysql_fetch_array($res,MYSQL_ASSOC)){
array_push($ary, $row);
}
}
return $ary;
}
function querySql($sql) {
$dbConfig = getServerInfo();
$con = mysql_connect($dbConfig['host'], $dbConfig["username"], $dbConfig['password']);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbConfig["database"]);
mysql_query("set names utf8", $con);
$res = mysql_query($sql, $con);
mysql_close($con);
return $res;
}
class User {
private $username;
private $password;
private $nicname;
private $lastlogin;
private $id;
function __construct($username, $password, $nicname) {
$this->username = $username;
$this->password = md5($password);
$this->nicname = $nicname;
}
function getUsername() {
return $this->username;
}
function getPassword() {
return $this->password;
}
function getNicname() {
return $this->nicname;
}
function getLastlogin() {
return $this->lastlogin;
}
function getId() {
return $this->id;
}
function setUsername($username) {
$this->username = $username;
}
function setPassword($password) {
$this->password = $password;
}
function setNicname($nicname) {
$this->nicname = $nicname;
}
function setLastlogin($lastlogin) {
$this->lastlogin = $lastlogin;
}
function setId($id) {
$this->id = $id;
}
}