PostgreSQL access with PHP/FI
All fields of the Cities table
City | Population | Altitude |
/* all PHP/FI commands are enclosed in with this tag */
/* making the connection to the database */
$conn = pg_Connect("localhost", "5432", "", "", "tutorial");
if (!$conn) {
echo "Couldn't establish connection to Database.\n";
exit;
}
/* posting the query */
$result = pg_Exec($conn, "select * from cities*");
if (!$result) {
echo "Error sending query!\n";
exit;
}
/* writing the data to a HTML-table */
$tuples = pg_NumRows($result);
$i=0;
while ($i < $tuples) {
$name = pg_Result($result, $i, "name");
$pop = pg_Result($result, $i, "population");
$alt = pg_Result($result, $i, "altitude");
echo "%s | %u | %u |
\n" $name, $pop, $alt;
$i++;
}
>
/* freeing ressources */
pg_FreeResult($result);
pg_Close($conn);
>