<?php
require_once __DIR__ . '/common.php';

$dbconn = getDBConnection();

// Performing SQL query
$query = "SELECT lat,lon,id,category,roadstatus,cwa,county,state,location,routename,description,lsr,date_trunc('minute', start) as start, date_trunc('minute', endtime) as endtime,date_trunc('minute', lastupdate) as lastupdate from ohgo where endtime is null or endtime > now() - interval '48 hours' order by start asc;";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());

// Printing results in HTML
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    $array[] = $line;
}
echo json_encode($array);

// Free resultset
pg_free_result($result);

// Close database connection when needed
if (isset($dbconn)) {
    pg_close($dbconn);
}
?>