27 lines
703 B
PHP
27 lines
703 B
PHP
<?php
|
|
// Connecting, selecting database
|
|
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws")
|
|
or die('Could not connect: ' . pg_last_error());
|
|
|
|
// Performing SQL query
|
|
$query = "SELECT sitename, lat, lon, tempf, humidity,raintotal,winddir,windspd,windgust,tempftime, humiditytime,raintotaltime,winddirtime,windspdtime,windgusttime FROM onerainsites where sitetype = 'MET';";
|
|
$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);
|
|
|
|
// Closing connection
|
|
pg_close($dbconn);
|
|
?>
|
|
|
|
|
|
|