-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_deliver.php
48 lines (41 loc) · 1.45 KB
/
gen_deliver.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
<?php
$response = array();
require_once ('db_constants.php');
if (isset($_GET['q']) && $_GET['q'] == SALT) {
// include db connect class
$bdd = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USERNAME, DB_PASSWORD);
$request = $bdd->query("SELECT value FROM ". TABLE_GENERAL . " WHERE name = 'timestamp'");
$row = $request->fetch();
// get all products from products table
/*$pre = mysql_query("SELECT value FROM cdr_gen WHERE name = 'timestamp'") or die(mysql_error());
$re = mysql_fetch_array($pre);*/
if (!isset($_GET['timestamp']) or strtotime($row['value']) != strtotime($_GET['timestamp'])) {
$clause = '';
//$result = mysql_query("SELECT * FROM cdr_gen") or die(mysql_error());
$request = $bdd->query("SELECT * FROM " .TABLE_GENERAL);
// check for empty result
//if (mysql_num_rows($result) > 0) {
if($request->rowCount() > 0) {
// looping through all results
// products node
//while ($row = mysql_fetch_array($result)) {
while ($row = $request->fetch()) {
// temp user array
$product = array();
$product["id"] = utf8_encode($row["id"]);
$product["name"] = utf8_encode($row["name"]);
$product["value"] = $row["value"];
// push single product into final response array
array_push($response, $product);
}
// success
// echoing JSON response
echo json_encode($response);
} else {
// no products found
// echo no uses JSON
echo json_encode($response);
}
}
}
?>