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