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);
?>
// 连接,选择数据库
$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);
?>
相关文章推荐
- java连接数据库Oracle|DB2|Sql Server|Sybase|Informix|MySQL||PostgreSQL|access
- Entity Freamwork 6连接PostgreSql数据库
- 解决Kali中msf连接postgresql数据库问题
- 解决Hibernate连接postgresql数据库慢的问题
- Python连接PostgreSQL数据库的方法
- Java连接postgresql数据库
- java连接postgreSQL数据库实例(转)
- libpq-PostgreSQL客户端编程接口(一)----libpq中的数据库连接函数
- JDBC连接PostgreSQL数据库的若干问题
- Entity Freamwork 6连接PostgreSql数据库
- java 使用jdbc连接Greenplum数据库和Postgresql数据库
- C#连接postgresql数据库
- Node.js 连接 postgreSQL数据库
- BT5之Metasploit[MSF]连接postgresql数据库
- JSP数据库连接方法(MySQL,MSSQL,Oracle,DB2,Informix,PostgreSQL,Sybase)
- 无法远程连接postgresql数据库
- Winform 动态读写xml config文件,连接数据库(postgresql)
- 关于数据库连接出错问题的解决方法(mysql、postgresql)
- hibernate 连接postgresql数据库
- JDBC连接之PostgreSQL数据库