mySQL Show PostgreSQL database tables
mySQL
Download (.zip)
<head> <title>Show PostgreSQL database tables</title> </head> <?php // Simple testscript which reads a PostgreSQL database table and outputs a HTML table. // v0.11 12-Aug-2002, by G. Knauf <efash@gmx.net> $host='localhost'; $user='postgres'; $pass=''; $dbase='webauth'; $table='user_pwd'; // Connecting to PostgreSQL database $conn = pg_connect("host=$host dbname=$dbase user=$user password=$pass "); if (!$conn) { echo "Error occured.\n"; exit; }
$result = pg_query ($conn, "SELECT * FROM $table"); if (!$result) { echo "Error occured.\n"; exit; }
$num = pg_num_rows($result); $nfields = pg_num_fields($result);
print "<h3>Table <font color=green>$table</font> contains <font color=blue>$num</font> records with <font color=blue>$nfields</font> fields:</h3>\n"; print "<table border>\n<tr>";
for ($i=0; $i < $nfields; $i++) { echo '<th>'.pg_field_name($result, $i).'</th>'; } print "</tr>\n";
for ($i=0; $i < $num; $i++) { echo '<tr>'; $r = pg_fetch_row($result, $i);
for ($j=0; $j < count($r); $j++) { echo '<td>'.$r[$j].' </td>'; }
print "</tr>\n"; } print "</table>\n"; ?>
|