1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- ini_set("display_errors", "0");
- //error_reporting(E_ALL);
- date_default_timezone_set('UTC');
- require("connection.php");
- // Opens a connection to a MySQL server
- $db = new PDO("mysql:host=$dbhost;dbname=$db;charset=utf8mb4", $dbuser, $dbpass);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $cache_file = "data.txt";
- $query = "SHOW TABLE STATUS FROM arduino LIKE 'markers'";
- $stmt = $db->query($query);
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
-
- if (file_exists($cache_file) && strtotime($row['Update_time']) <= filemtime ($cache_file)) {
-
- header("Location: $cache_file?cache=" . filemtime ($cache_file));
- die();
- } else {
- // Select all the rows in the markers table
- $query = "SELECT * FROM markers ORDER BY timestamp";
- $stmt = $db->query($query);
- // Iterate through the rows, adding XML nodes for each
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- $row['lat'] = doubleval($row['lat']);
- $row['lng'] = doubleval($row['lng']);
- $row['alt'] = floatval($row['alt']);
- $row['hdop'] = intval($row['hdop']);
- $row['timestamp'] = strtotime($row['timestamp']);
- //$row['format'] = date('d.m.Y H:i:s', $row['timestamp']);
- $json[] = $row;
- }
- $txt=json_encode($json);
- file_put_contents($cache_file, $txt, LOCK_EX);
- echo $txt;
- }
- ?>
|