-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexample.php
71 lines (53 loc) · 1.67 KB
/
example.php
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
62
63
64
65
66
67
68
69
70
71
<?php
# Example PHP to query indi-allsky database
# Requires packages
# * php-sqlite3
# * php-json
header("Content-Type: application/json");
class IndiAllSkyLatestImages {
public $db_uri = 'sqlite:/var/lib/indi-allsky/indi-allsky.sqlite';
public $cameraId = 2;
public $limit = 1;
public $rootpath = '/var/www/html/allsky/'; # this needs to end with /
private $_conn;
public function __construct() {
$this->_conn = $this->_dbConnect();
}
private function _dbConnect() {
$conn = new PDO($this->db_uri);
$conn->exec('PRAGMA journal_mode=WAL');
return($conn);
}
public function getLatestImages() {
$stmt_files = $this->_conn->prepare("
SELECT
image.filename AS image_filename
FROM image
JOIN camera
ON camera.id = image.camera_id
WHERE
camera.id = :cameraId
ORDER BY
image.createDate DESC
LIMIT
:limit
");
$stmt_files->bindParam(':cameraId', $this->cameraId, PDO::PARAM_INT);
$stmt_files->bindParam(':limit', $this->limit, PDO::PARAM_INT);
$stmt_files->execute();
$image_list = array();
while($row = $stmt_files->fetch()) {
$filename = $row['image_filename'];
if (! file_exists($filename)) {
continue;
}
$relpath = str_replace($this->rootpath, '', $filename);
$image_list[] = $relpath;
}
return($image_list);
}
}
$x = new IndiAllSkyLatestImages();
$json_data = $x->getLatestImages();
print(json_encode($json_data));
?>