fixed closing sqlite3 database
[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 (isset($_REQUEST["P"]))
13   $OFFSET = "".($_REQUEST["P"]*$N-$N).",";
14 else
15   $OFFSET = "";
16
17 if($usePDO)
18   $DB = new PDO("sqlite:$DBFILE");
19 else
20   $DB = new SQlite3($DBFILE);
21
22 $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET $N");
23
24 $row = array();
25
26 $i = 0;
27
28 if(!$usePDO)
29   {
30     /* convert results into array */
31     $tmp=array();
32     while($res = $result->fetchArray(SQLITE3_ASSOC)){
33       $tmp[]=$res;
34     }
35     $result=$tmp;
36   }
37
38 foreach ($result as $res)
39 {
40   $row[$i] = $res;
41   $i++;
42 }
43
44
45 echo json_encode($row);
46
47 /* close the database */
48 if($usePDO)
49   $DB=null;
50 else
51   $DB->close();
52
53 ?>
54