summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2011-11-24 10:06:32 -0800
committerArun Persaud <apersaud@lbl.gov>2011-11-24 10:09:40 -0800
commit78ab005390d15e706f68d2beabfa0a4ad79e0703 (patch)
tree7f8fcffdd2826dac07ef205039319dc0af257bab
parentf55f4ad4dacb726861a7e6c34a471d468d2e24d3 (diff)
downloadphoto-tags-78ab005390d15e706f68d2beabfa0a4ad79e0703.tar.gz
photo-tags-78ab005390d15e706f68d2beabfa0a4ad79e0703.tar.bz2
photo-tags-78ab005390d15e706f68d2beabfa0a4ad79e0703.zip
option to use PDO connections to sqlite when connecting via php
-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);
+
?>