option to use PDO connections to sqlite when connecting via php
[photo-tags.git] / getjson.php
index ce0c6e0a04f8cccbde0490efae54bac74af756d1..cbb9feea559cc144bf756dfb1a89e021e92dd65f 100644 (file)
@@ -3,6 +3,7 @@
 /* parse ini -file */
 $iniarray=parse_ini_file("config.ini");
 $DBFILE=$iniarray["fspotdb"];
+$usePDO=$iniarray["usePDO"];
 /* end parse ini-file */
 
 if (isset($_REQUEST["O"]))
@@ -15,18 +16,29 @@ if (isset($_REQUEST["N"]))
 else
   $N= 25;
 
-$DB = new SQlite3($DBFILE);
+if($usePDO)
+  $DB = new PDO("sqlite:$DBFILE");
+else
+  $DB = new SQlite3($DBFILE);
 
 $result = $DB->query("SELECT * FROM photos LIMIT $O $N");
 
-sqlite_close(DB);
-
 $row = array();
 
 $i = 0;
 
-while($res = $result->fetchArray(SQLITE3_ASSOC)){
-    
+if(!$usePDO)
+  {
+    /* convert results into array */
+    $tmp=array();
+    while($res = $result->fetchArray(SQLITE3_ASSOC)){
+      $tmp[]=$res;
+    }
+    $result=$tmp;
+  }
+
+foreach ($result as $res){
+
   $row[$i] = $res;
  
   $i++;
@@ -36,5 +48,11 @@ while($res = $result->fetchArray(SQLITE3_ASSOC)){
 
 echo json_encode($row);
 
+/* close the database */
+if($usePDO)
+  $DB=null;
+else
+  sqlite_close($DB);
+
 ?>