summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.ini_template1
-rw-r--r--getjson.php28
2 files changed, 24 insertions, 5 deletions
diff --git a/config.ini_template b/config.ini_template
index 6a36ebf..bdbf94d 100644
--- a/config.ini_template
+++ b/config.ini_template
@@ -4,6 +4,7 @@
fspotdb="myphoto.db"
origdb="/home/username/.config/f-spot-photos.db"
dbprefix=""
+usePDO=0
[local]
dirprefix=""
diff --git a/getjson.php b/getjson.php
index ce0c6e0..cbb9fee 100644
--- a/getjson.php
+++ b/getjson.php
@@ -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);
+
?>