4 $db = new SQLiteDatabase("sql/imgorg.db");
6 $res = $db->query('select * from Albums');
8 while ($o = $res->fetchObject()) {
15 function addOrUpdate($data){
16 $db = new SQLiteDatabase('sql/imgorg.db');
17 $q = $db->query('SELECT * FROM Albums where id = "'.$data->id.'"');
18 if (sizeof($q) == 0) {
19 $res = $db->query('INSERT INTO Albums (text) VALUES ("'.$data->text.'")');
21 $res = $db->query('UPDATE Albums SET text ="'.$data->text.'" WHERE id = "'.$data->id.'"');
23 return array(success => true);
26 function remove($data) {
27 $db = new SQLiteDatabase('sql/imgorg.db');
28 $q = $db->queryExec('DELETE FROM Albums where id ="'.$data->album.'"');
29 return array(success=>true, album => $data->album);
33 // use $query for type-ahead
34 $query = $data->query;
35 $db = new SQLiteDatabase('sql/imgorg.db');
36 $qryStr = 'SELECT * FROM Albums';
38 $qryStr .= ' where text like "'.$query.'%"';
40 $q = $db->query($qryStr);
41 return $q->fetchAll();
44 function getAlbums($data) {
45 $db = new SQLiteDatabase('sql/imgorg.db');
46 $image = $data->image;
48 $q = $db->query('SELECT a.text as text, a.id as id FROM Albums a INNER JOIN Images i ON a.id = i.album_id WHERE i.id = "'.$image.'"');
49 return $q->fetchAll();
52 function getAllInfo($data) {
53 $db = new SQLiteDatabase('sql/imgorg.db');
54 $res = $db->query('select * from Albums');
56 while ($o = $res->fetchObject()) {
57 $q = $db->query('SELECT * FROM Images WHERE album_id = "'.$o->id.'"');
58 $qres = $q->fetchObject();
61 $filename = '../'.$path;
62 if (file_exists($filename)) {
63 $o->exif = exif_read_data($filename);
65 $o->filename = $qres->filename;
67 $o->size = sizeof($q->fetchAll());