您的位置:首页 > 数据库

postgreSQL连接数据库

2012-07-16 17:53 232 查看
<?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);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: