-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.inc.php
67 lines (57 loc) · 1.54 KB
/
db.inc.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
<?php
class DB {
function __construct($dbname)
{
if (!file_exists($dbname))
{
$newfile = true;
} else {
$newfile = false;
}
if ($this->db = sqlite_popen($dbname, 0777, $sqliteerror))
{
if ($newfile)
$this->query('CREATE TABLE card (firstname varchar(100), surname varchar(100), firm varchar(100), mobilep varchar(20), workp varchar(20), privatep varchar(20), email varchar(65));');
} else {
die($sqliteerror);
}
}
function __destruct()
{
sqlite_close($this->db);
}
function query($query)
{
//return sqlite_array_query($this->db, $query);
$res = sqlite_query($this->db, $query);
if ($res == FALSE) {
echo(sprintf("query: %s\nsqlite error: %s\n", $query, sqlite_error_string(sqlite_last_error($this->db))));
return NULL;
}
return sqlite_fetch_all($res);
}
function last_rowid()
{
return sqlite_last_insert_rowid($this->db);
}
function get_card_ids ()
{
return $this->query("SELECT rowid FROM card WHERE 1 ORDER BY surname ASC, firstname ASC;");
}
function search_card($needle)
{
return $this->query("SELECT rowid FROM card WHERE
firstname LIKE '%".$needle."%' OR
surname LIKE '%".$needle."%' OR
firm LIKE '%".$needle."%' OR
mobilep LIKE '%".$needle."%' OR
workp LIKE '%".$needle."%' OR
privatep LIKE '%".$needle."%' OR
email LIKE '%".$needle."%';");
}
function card_update($id, $field, $newvalue)
{
$this->query("UPDATE card SET ".$field."='".$newvalue."' WHERE rowid='".$id."';");
}
}
?>