<?php
// 连接,选择数据库
$db = pg_connect ( "host=localhost dbname=publishing user=www password=foo" );
or die( 'Could not connect: ' . pg_last_error ());
// 执行 SQL 查询
$query = 'SELECT * FROM authors' ;
$result = pg_query ( $query ) or die( 'Query failed: ' . pg_last_error ());
// 用 HTML 显示结果
echo "<table>\n" ;
while ( $line = pg_fetch_array ( $result , null , PGSQL_ASSOC )) {
echo "\t<tr>\n" ;
foreach ( $line as $col_value ) {
echo " \t\t <td>$col_value</td> \n " ;
}
echo "\t</tr>\n" ;
}
echo "</table>\n" ;
// 释放结果集
pg_free_result ( $result );
// 关闭连接
pg_close ( $link );
?>
// 连接,选择数据库
$db = pg_connect ( "host=localhost dbname=publishing user=www password=foo" );
or die( 'Could not connect: ' . pg_last_error ());
// 执行 SQL 查询
$query = 'SELECT * FROM authors' ;
$result = pg_query ( $query ) or die( 'Query failed: ' . pg_last_error ());
// 用 HTML 显示结果
echo "<table>\n" ;
while ( $line = pg_fetch_array ( $result , null , PGSQL_ASSOC )) {
echo "\t<tr>\n" ;
foreach ( $line as $col_value ) {
echo " \t\t <td>$col_value</td> \n " ;
}
echo "\t</tr>\n" ;
}
echo "</table>\n" ;
// 释放结果集
pg_free_result ( $result );
// 关闭连接
pg_close ( $link );
?>