-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.upload.dao.php
106 lines (90 loc) · 2.84 KB
/
class.upload.dao.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
<?php
/* DAO for upload */
include ("class.upload.vo.php");
class DAOupload {
/* gets a vo by upload_id */
public function get($upload_id){
/* ensure upload_id is an integer */
if(!is_numeric($upload_id)) throw new Exception("upload_id of upload must be an integer");
$result=mysql_query("SELECT * FROM upload WHERE upload_id=$upload_id");
if($result){/*ensure query success*/
if($row = mysql_fetch_array($result)){/*ensure record*/
$vo = new upload($row['uid'],$row['title'],$row['type'],$row['date'],$row['img']);
$vo->upload_id = $upload_id;
return $vo;
}
}
return NULL;
}
/* returns all vo */
public function getAll($limit1,$limit2){
$result=mysql_query("SELECT * FROM upload LIMIT " . $limit1 . "," . $limit2 );
if($result){/*ensure query success*/
$vlist = array();
while($row = mysql_fetch_array($result)){/*ensure record*/
$vo = new upload($row['uid'],$row['title'],$row['type'],$row['date'],$row['img']);
$vo->upload_id = $row['upload_id'];
$vlist[] = $vo;
}
return $vlist;
}
return NULL;
}
/* returns all vo by user*/
public function getAllByUser($uid,$limit1,$limit2){
$result=mysql_query("SELECT * FROM upload where uid=$uid LIMIT " . $limit1 . "," . $limit2 );
if($result){/*ensure query success*/
$vlist = array();
while($row = mysql_fetch_array($result)){/*ensure record*/
$vo = new upload($row['uid'],$row['title'],$row['type'],$row['date'],$row['img']);
$vo->upload_id = $row['upload_id'];
$vlist[] = $vo;
}
return $vlist;
}
return NULL;
}
/* returns number of vo */
public function getCount(){
$result = mysql_num_rows(mysql_query("select * from upload"));
return $result;
}
/* insert new record in db */
public function insert(&$vo){
if(mysql_query("INSERT INTO upload(upload_id,uid,title,type,date,img) VALUES(' ', '$vo->uid','$vo->title','$vo->type','$vo->date','$vo->img')")){
$result = mysql_query("Select MAX(upload_id) from upload");
if($row = mysql_fetch_array($result)){
$vo->upload_id=$row[0];
return true;
}
}
return false;
}
/* update an existing record in db */
public function update(&$vo){
return mysql_query("UPDATE upload SET uid = '$vo->uid',title = '$vo->title',type = '$vo->type',date = '$vo->date',img = '$vo->img' WHERE upload_id = $vo->upload_id ");
}
/* save the value object in db */
public function save(&$vo){
if($vo->upload_id == 0){
return $this->insert($vo);
}
return $this->update($vo);
}
/* delete an existing record from db */
public function del(&$vo){
if(mysql_query("DELETE FROM upload WHERE upload_id=$vo->upload_id")) {
$vo->upload_id=0;
}
}
/* gets max id from db */
public function getMaxId(){
$result = mysql_query("Select MAX(upload_id) from upload");
if($row = mysql_fetch_array($result)){
return $row[0];
}
return NULL;
}
}
/* DAOupload */
?>