-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateEventDao.php
45 lines (43 loc) · 1.15 KB
/
UpdateEventDao.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
<?php
class UpdateEventDao {
private $table = "atp_update_event";
public function __construct($link) {
$this->link = $link;
}
public function getAll() {
$query = "SELECT * FROM ".$this->table." ORDER BY id";
$dbRes=mysqli_query($this->link, $query);
$result = array();
while ($row=mysqli_fetch_array($dbRes)) {
$result []= new UpdateEvent($row);
}
return $result;
}
public function getLast() {
$query = "SELECT * FROM ".$this->table." ORDER BY id desc limit 1";
$dbRes=mysqli_query($this->link, $query);
while ($row=mysqli_fetch_array($dbRes)) {
return new UpdateEvent($row);
}
return null;
}
public function add($certificate) {
$query = "INSERT INTO ".$this->table." (date) values (";
$query .= $this->prepareDate($certificate->getDate())." ";
$query .= ");" ;
mysqli_query($this->link, $query);
}
public function clear() {
$query="DELETE FROM ".$this->table.";";
mysqli_query($this->link, $query);
}
protected function prepareDate($str) {
if ($str ==null) {
return "null";
} else {
$result = date("Y-m-d H:i:s", strtotime($str));
return " '$result' ";
}
}
}
?>