summaryrefslogtreecommitdiffstats
path: root/getjson.php
blob: 0b414be61d106e435b24f109de52fcfca2366015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?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($usePDO)
  $DB = new PDO("sqlite:$DBFILE");
else
  $DB = new SQlite3($DBFILE);


/* do database query */
if (isset($_REQUEST["P"]))
  {
    $OFFSET = "".($_REQUEST["P"]*$N-$N);

    $result = $DB->query("SELECT * FROM photos LIMIT $OFFSET, $N");
  }
else if (isset($_REQUEST["T"]))
  {
    $result = $DB->query("SELECT count(*) as total FROM photos");
  }
else
  $result=null;

/* encode result as an array */
$tmp=array();
if(!$usePDO)
  {
    /* convert results into array */
    while($res = $result->fetchArray(SQLITE3_ASSOC))
      {
	$tmp[]=$res;
      }
  }
else
  {
    foreach($result as $res)
      {
        $tmp[]=$res;
      }
  }
$result=$tmp;

echo json_encode($result);

/* close the database */
if($usePDO)
  $DB=null;
else
  $DB->close();


?>