-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
52 lines (46 loc) · 1.11 KB
/
database.php
File metadata and controls
52 lines (46 loc) · 1.11 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
<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open('log.db');
}
}
$db = new MyDB();
if (!$db) {
echo $db->lastErrorMsg();
}
$sql = <<<EOF
CREATE TABLE IF NOT EXISTS t_file(
md5 CHAR(32) PRIMARY KEY NOT NULL,
uid INT NOT NULL,
original_name CHAR(256),
size INT NOT NULL,
filename CHAR(256) NOT NULL,
create_time TIMESTAMP NOT NULL DEFAULT current_timestamp,
update_time TIMESTAMP NOT NULL DEFAULT current_timestamp
);
EOF;
$ret = $db->exec($sql);
if (!$ret) {
echo $db->lastErrorMsg();
}
function newLog($db, $md5, $uid, $ori, $size, $filename)
{
$sql = sprintf("INSERT OR REPLACE INTO t_file (md5,uid,original_name,size,filename) VALUES ('%s',%d,'%s',%d,'%s' );", $md5, $uid, $ori, $size, $filename);
$ret = $db->exec($sql);
if (!$ret) {
echo $db->lastErrorMsg();
}
return $ret;
}
function delLog($db, $md5)
{
$sql = sprintf("DELETE from t_file WHERE md5='%s';", $md5);
$ret = $db->exec($sql);
if (!$ret) {
echo $db->lastErrorMsg();
}
return $ret;
}
?>