ryxeo-webphotoalbum-git / data / www / inc / db.class.inc.php @ 7938c308
Historique | Voir | Annoter | Télécharger (1,59 ko)
1 | 67466a8d | Eric Seigne | <?php
|
---|---|---|---|
2 | /* SQLite DB class for storing
|
||
3 | - image views,
|
||
4 | - user comments
|
||
5 | */
|
||
6 | |||
7 | $dbfile = "$root/$gallery_dir/photos.db"; |
||
8 | |||
9 | //unfortunately in php4, the SQLiteDatabse class isn't created so we have to
|
||
10 | |||
11 | class SQLiteDatabase { |
||
12 | var $dbfile; |
||
13 | |||
14 | function SQLiteDatabase ($dbfile) { |
||
15 | |||
16 | $this->dbfile = $dbfile; |
||
17 | //if db file doesn't exist, fill with skeleton
|
||
18 | if (file_exists($this->dbfile)) { |
||
19 | $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); |
||
20 | } else {
|
||
21 | //fill with skeleton
|
||
22 | $folder = dirname($this->dbfile); |
||
23 | if (!is_writable($folder)) { //we need write permission to create database |
||
24 | die("<p style=\"color:red;\">cannot create dabase. check permissions.</p>\n"); |
||
25 | } else {
|
||
26 | $this->dbres = sqlite_open($this->dbfile, 0666, $sqliteerror); |
||
27 | //photo table
|
||
28 | $sql = "create table photo (id INTEGER PRIMARY KEY, caption TEXT, "; |
||
29 | $sql .= "counter INTEGER, number INTEGER, album TEXT, name TEXT)"; |
||
30 | $this->query($sql); |
||
31 | //comment table
|
||
32 | $sql = "create table comment (id INTEGER PRIMARY KEY, user TEXT, "; |
||
33 | $sql .= "comment_body TEXT, photo_id INT, date DATETIME)"; |
||
34 | $this->query($sql); |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 | |||
39 | function query($sql) { |
||
40 | global $page; |
||
41 | |||
42 | if (!$this->result = sqlite_query($this->dbres, $sql)) { |
||
43 | print "Query failed, <span style=\"color: blue;\"><pre>$sql</pre></style>\n"; |
||
44 | print sqlite_error_string (sqlite_last_error($this->dbres)); |
||
45 | $page->footer();
|
||
46 | exit;
|
||
47 | } |
||
48 | } |
||
49 | |||
50 | function count() { |
||
51 | return sqlite_num_rows($this->result); |
||
52 | } |
||
53 | |||
54 | function rewind() { //just to abstract from sqlite |
||
55 | sqlite_rewind($this->result);
|
||
56 | } |
||
57 | |||
58 | } |
||
59 | |||
60 | |||
61 | $db = new SQLiteDatabase("$dbfile"); |
||
62 | |||
63 | ?> |