option to use PDO connections to sqlite when connecting via php
authorArun Persaud <arun@nubati.net>
Thu, 24 Nov 2011 18:06:32 +0000 (10:06 -0800)
committerArun Persaud <apersaud@lbl.gov>
Thu, 24 Nov 2011 18:09:40 +0000 (10:09 -0800)
config.ini_template
getjson.php

index 6a36ebf0d587bb4738cad68e99889bb2be283a39..bdbf94d1463388ea2f13a72adde76dd91f7c9180 100644 (file)
@@ -4,6 +4,7 @@
 fspotdb="myphoto.db"
 origdb="/home/username/.config/f-spot-photos.db"
 dbprefix=""
 fspotdb="myphoto.db"
 origdb="/home/username/.config/f-spot-photos.db"
 dbprefix=""
+usePDO=0
 
 [local]
 dirprefix=""
 
 [local]
 dirprefix=""
index ce0c6e0a04f8cccbde0490efae54bac74af756d1..cbb9feea559cc144bf756dfb1a89e021e92dd65f 100644 (file)
@@ -3,6 +3,7 @@
 /* parse ini -file */
 $iniarray=parse_ini_file("config.ini");
 $DBFILE=$iniarray["fspotdb"];
 /* parse ini -file */
 $iniarray=parse_ini_file("config.ini");
 $DBFILE=$iniarray["fspotdb"];
+$usePDO=$iniarray["usePDO"];
 /* end parse ini-file */
 
 if (isset($_REQUEST["O"]))
 /* end parse ini-file */
 
 if (isset($_REQUEST["O"]))
@@ -15,18 +16,29 @@ if (isset($_REQUEST["N"]))
 else
   $N= 25;
 
 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");
 
 
 $result = $DB->query("SELECT * FROM photos LIMIT $O $N");
 
-sqlite_close(DB);
-
 $row = array();
 
 $i = 0;
 
 $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++;
   $row[$i] = $res;
  
   $i++;
@@ -36,5 +48,11 @@ while($res = $result->fetchArray(SQLITE3_ASSOC)){
 
 echo json_encode($row);
 
 
 echo json_encode($row);
 
+/* close the database */
+if($usePDO)
+  $DB=null;
+else
+  sqlite_close($DB);
+
 ?>
 
 ?>