-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAccessLogAPI.php
More file actions
47 lines (39 loc) · 1.16 KB
/
AccessLogAPI.php
File metadata and controls
47 lines (39 loc) · 1.16 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
<?php
class AccessLogAPI {
function setPDO($db) {
$this->db = $db;
}
function deleteById($id) {
$db = $this->db;
$stmt = $db->prepare("DELETE FROM api_log WHERE id = ?");
$stmt->execute(array($id));
return $stmt->rowCount();
return 1;
}
function insert($value_array) {
$sql = "INSERT INTO api_log(ip, service_name, `datetime`, response_time,response_massage) VALUES (:ip,:service_name,:datetime,:response_time,:response_massage)";
$q = $this->db->prepare($sql);
return $q->execute(
[
':ip'=>$value_array['ip'],
':service_name'=>$value_array['service_name'],
':datetime'=>$value_array['datetime'],
':response_time'=>$value_array['response_time'],
':response_massage'=>$value_array['response_massage']
]
);
}
function updateById($id, $keys, $values){
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$update = "";
foreach($keys as $key) {
if($update!="") $update .= ", ";
$update .= $key."=?";
}
$stmt = $this->db->prepare("UPDATE api_log SET ".$update." where id=?");
$params = array_merge($values, array($id));
$stmt->execute($params);
return $stmt->rowCount();
}
}
?>