1 | <?php |
---|
2 | /* The SQLite extension is enabled by default as of PHP 5. |
---|
3 | * Before that time the SQLite library is needed. |
---|
4 | * |
---|
5 | * For more info on setting up SQLite See: |
---|
6 | * http://www.php.net/manual/en/sqlite.installation.php |
---|
7 | * |
---|
8 | */ |
---|
9 | if ($db = new SQLiteDatabase('imgorg.db')) { |
---|
10 | // Albums |
---|
11 | // $db->queryExec('DROP TABLE Albums'); |
---|
12 | $db->queryExec('CREATE TABLE Albums ( |
---|
13 | id INTEGER PRIMARY KEY, |
---|
14 | text STRING, |
---|
15 | created STRING, |
---|
16 | description TEXT |
---|
17 | ); |
---|
18 | INSERT INTO Albums (text) VALUES ("Test"); |
---|
19 | INSERT INTO Albums (text) VALUES ("Album2");'); |
---|
20 | |
---|
21 | // Albums_Images |
---|
22 | // $db->queryExec('DROP TABLE Albums_Images'); |
---|
23 | $db->queryExec('CREATE TABLE Albums_Images ( |
---|
24 | album_id INTEGER, |
---|
25 | image_id INTEGER |
---|
26 | )'); |
---|
27 | |
---|
28 | // Images_Tags |
---|
29 | $db->queryExec('CREATE TABLE Images_Tags ( |
---|
30 | tag_id INTEGER, |
---|
31 | image_id INTEGER |
---|
32 | )'); |
---|
33 | |
---|
34 | // Tags |
---|
35 | // $db->queryExec('DROP Table Tags'); |
---|
36 | $db->queryExec('CREATE TABLE Tags ( |
---|
37 | id INTEGER PRIMARY KEY, |
---|
38 | text STRING |
---|
39 | ); |
---|
40 | INSERT INTO Tags (text) VALUES("Family"); |
---|
41 | INSERT INTO Tags (text) VALUES("Friends"); |
---|
42 | INSERT INTO Tags (text) VALUES("Other")'); |
---|
43 | |
---|
44 | // Images |
---|
45 | // $db->queryExec('DROP TABLE Images'); |
---|
46 | $db->queryExec('CREATE TABLE Images ( |
---|
47 | id INTEGER PRIMARY KEY, |
---|
48 | filename STRING, |
---|
49 | url STRING, |
---|
50 | album_id INTEGER, |
---|
51 | description TEXT |
---|
52 | )'); |
---|
53 | |
---|
54 | // $dir = "../../images/thumbs/"; |
---|
55 | // $images = array(); |
---|
56 | // $d = dir($dir); |
---|
57 | // $i = 0; |
---|
58 | // while($name = $d->read()){ |
---|
59 | // if(!preg_match('/\.(jpg|gif|png)$/', $name)) continue; |
---|
60 | // $size = filesize($dir.$name); |
---|
61 | // $lastmod = filemtime($dir.$name)*1000; |
---|
62 | // $db->queryExec('INSERT INTO Images (filename, url) VALUES |
---|
63 | // ("'.$name.'","images/thumbs/'.$name.'")'); |
---|
64 | // } |
---|
65 | // $d->close(); |
---|
66 | |
---|
67 | |
---|
68 | echo json_encode($db->query('select * from Images')->fetchAll()); |
---|
69 | } else { |
---|
70 | die($err); |
---|
71 | } |
---|
72 | |
---|