forked from LamCiuLoeng/BookShare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_helper.php
More file actions
61 lines (50 loc) · 1.88 KB
/
db_helper.php
File metadata and controls
61 lines (50 loc) · 1.88 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
<?php
function getDownloadBooks($db,$user_id){
$sql = "SELECT b.* from books b, user_book ub where ub.active=0 and b.id=ub.book_id and ub.user_id=$user_id";
return $db->get_results($sql);
}
function getUploadBooks($db,$user_id){
$sql = "SELECT b.* from books b , user_book ub where b.active=0 and b.id=ub.book_id and ub.user_id=$user_id";
return $db->get_results($sql);
}
function getDownloadBook($db,$user_id,$book_id) {
$sql = "select * from user_book where user_id=$user_id and book_id=$book_id";
return $db->get_row($sql);
}
function getUserInfo($db,$user_id){
$sql = "select * from users where id=$user_id";
return $db->get_row($sql);
}
function getAllUsers($db) {
$sql = "select * from users where active=0;";
return $db->get_results($sql);
}
function getAllBooks($db){
$sql = "SELECT b.*,u.email from books b,users u WHERE b.active=0 and u.active=0 and b.create_by=u.id";
return $db->get_results($sql);
}
function addBook($db,$name,$desc,$short_desc,$path,$point,$create_by){
$sql = "insert into books(name,description,short_description,path,points,create_by) values ('$name','$desc','$short_desc','$path',$point,$create_by);";
$db->query($sql);
return $db->rows_affected;
}
function addDownloadTime($db,$book_id){
$sql = "update books set download_times=download_times+1 where id=$book_id";
$db->query($sql);
return $db->rows_affected;
}
function addDownloadHistory($db,$user_id,$book_id,$points){
$sql = "insert into user_book (user_id,book_id,points) values ($user_id,$book_id,$points)";
$db->query($sql);
return $db->rows_affected;
}
function updateUserPoints($db,$user_id,$points){
$sql = "update users set points=points+($points) where id=$user_id";
$db->query($sql);
return $db->rows_affected;
}
function getAllCategories($db){
$sql = "select * from categories where active=0";
return $db->get_results($sql);
}
?>