<?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
);
?>