prepare('INSERT INTO `fm_temperature` (`temp_celcius`) VALUES (:temp)'); $insert->bindValue('temp', (string)json_decode($temp)); $insert->execute(); return; } if(isset($_GET['since'])) { $since = (int)filter_input(INPUT_GET, 'since', FILTER_SANITIZE_NUMBER_INT); $temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` WHERE `temp_datetime` > FROM_UNIXTIME(:since) AND `temp_datetime` > NOW() - INTERVAL 1 DAY ORDER BY `temp_datetime` ASC LIMIT 288'); $temps->bindValue('since', $since); $temps->execute(); header('Content-Type: application/json; charset=utf-8'); echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); return; } if(!empty($_GET['siri'])) { header('Content-Type: text/plain; charset=utf-8'); $temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` ORDER BY `temp_datetime` DESC LIMIT 1'); $temps->execute(); $temps = $temps->fetch(PDO::FETCH_ASSOC); printf('It was %2$.1f°C at %1$s.', date('H:i:s', $temps['temp_datetime']), $temps['temp_celcius']); return; } ?>