<?php
+$N=30;
+
/* parse ini -file */
$iniarray=parse_ini_file("config.ini");
$DBFILE=$iniarray["fspotdb"];
+$usePDO=$iniarray["usePDO"];
+$N=$iniarray["pics_per_page"];
/* end parse ini-file */
-if (isset($_REQUEST["O"]))
- $O = "".$_REQUEST["O"].",";
+if (isset($_REQUEST["P"]))
+ $OFFSET = "".($_REQUEST["P"]*$N-$N).",";
else
- $O="";
+ $OFFSET = "";
-if (isset($_REQUEST["N"]))
- $N = "".$_REQUEST["N"];
+if($usePDO)
+ $DB = new PDO("sqlite:$DBFILE");
else
- $N= 25;
-
-$DB = new SQlite3($DBFILE);
-
-$result = $DB->query("SELECT * FROM photos LIMIT $O $N");
+ $DB = new SQlite3($DBFILE);
-sqlite_close(DB);
+$result = $DB->query("SELECT * FROM photos LIMIT $OFFSET $N");
$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++;
-
- }
+}
echo json_encode($row);
+/* close the database */
+if($usePDO)
+ $DB=null;
+else
+ sqlite_close($DB);
+
?>