} $db = new MyDB(); if (!$db) { echo $db->lastErrorMsg(); } else { // echo "Opened database successfully\n"; } $sql = <<<EOF SELECT * from temp order by id desc limit 288; EOF; $ret = $db->query($sql); $array_string_temperature = ""; $array_string_timestamp = ""; while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { $array_string_temperature[] = $row["temperature"]; $time_string = date('Y-m-d H:i', strtotime(getLocaltime($row["timestamp"]))); $array_string_timestamp[] = strtotime($time_string); } $db->close(); $ydata = array_reverse($array_string_temperature); $xdata = array_reverse($array_string_timestamp); function getLocaltime($utc_time) { $utc_date = DateTime::createFromFormat('Y-m-d H:i:s', $utc_time, new DateTimeZone('UTC')); $local_date = $utc_date; $local_date->setTimeZone(new DateTimeZone('Europe/Helsinki')); $timestamp_string = $local_date->format('Y-m-d H:i:s'); return $timestamp_string; } require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php';
function getLocaltime($utc_time) { $utc_date = DateTime::createFromFormat('Y-m-d H:i:s', $utc_time, new DateTimeZone('UTC')); $local_date = $utc_date; $local_date->setTimeZone(new DateTimeZone('Europe/Helsinki')); $timestamp_string = $local_date->format('l jS \\of F Y H:i'); return $timestamp_string; } $db = new MyDB(); if (!$db) { echo $db->lastErrorMsg(); } else { // echo "Opened database successfully\n"; } $sql = <<<EOF SELECT * from temp order by id desc limit 1; EOF; $ret = $db->query($sql); while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { echo getLocaltime($row['timestamp']) . " : " . round($row['temperature'], 1) . "°C"; } // echo "Operation done successfully\n"; $db->close(); ?> <br /> <img src="temp_graph.php?_jpg_csimd=1" /> </center> </body> </html>