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; } ?>