0b414be61d106e435b24f109de52fcfca2366015
[photo-tags.git] / getjson.php
1 <?php
2
3 $N=30;
4
5 /* parse ini -file */
6 $iniarray=parse_ini_file("config.ini");
7 $DBFILE=$iniarray["fspotdb"];
8 $usePDO=$iniarray["usePDO"];
9 $N=$iniarray["pics_per_page"];
10 /* end parse ini-file */
11
12 if($usePDO)
13   $DB = new PDO("sqlite:$DBFILE");
14 else
15   $DB = new SQlite3($DBFILE);
16
17
18 /* do database query */
19 if (isset($_REQUEST["P"]))
20   {
21     $OFFSET = "".($_REQUEST["P"]*$N-$N);
22
23     $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
24   }
25 else if (isset($_REQUEST["T"]))
26   {
27     $result = $DB->query("SELECT count(*) as total FROM photos");
28   }
29 else
30   $result=null;
31
32 /* encode result as an array */
33 $tmp=array();
34 if(!$usePDO)
35   {
36     /* convert results into array */
37     while($res = $result->fetchArray(SQLITE3_ASSOC))
38       {
39         $tmp[]=$res;
40       }
41   }
42 else
43   {
44     foreach($result as $res)
45       {
46         $tmp[]=$res;
47       }
48   }
49 $result=$tmp;
50
51 echo json_encode($result);
52
53 /* close the database */
54 if($usePDO)
55   $DB=null;
56 else
57   $DB->close();
58
59
60 ?>
61