From: Arun Persaud Date: Thu, 24 Nov 2011 18:06:32 +0000 (-0800) Subject: option to use PDO connections to sqlite when connecting via php X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=commitdiff_plain;h=78ab005390d15e706f68d2beabfa0a4ad79e0703 option to use PDO connections to sqlite when connecting via php --- 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); + ?>