<?php
//FUNCTION: Connect to PostgreSql database
//AUTHOR: lucas.liu
//DATETIME: 2007-10-31
//create a connection to postgresql database
$dbconn = pg_connect("host=localhost dbname=postgres user=postgres password=831025")
or die('Could not connect:'.pg_last_error());
//query data from postgresql database
$query = 'SELECT * FROM weather ';
$result = pg_query($query) or die('Query failed:'.pg_last_error());
//fetch data from postgresql database
echo "<table border='1'>";
while($row = pg_fetch_array($result,null,PGSQL_ASSOC)){
echo "<tr>";
foreach($row as $value){
echo "<td style='color:blue'>".$value."</td>";
}
echo "</tr>";
}
echo "</table>";
//release query result
pg_free_result($result);
//close connection to postgresql database
pg_close($dbconn);
?>