php连接postgresql

在ubuntu下用php连接postgresql需要下个模块php5-pgsql

连接数据库并显示一张表的内容:

<?php
#连接数据库
$conn = pg_connect("host=localhost port=5432 dbname=test1 user=jm password=123");
if (!$conn)
echo "连接失败!!!!!<br>";
else
echo "连接成功=====@@@@======<br>"; #执行查询语句
$sql="select * from book";
$ret = pg_query($conn, $sql); #显示数据表
while($row = pg_fetch_row($ret)){
echo "ID = ". $row[0] . "\n";
echo "NAME = ". $row[1] ."\n";
echo "ADDRESS = ". $row[2] ."\n";
echo "SALARY = ".$row[4] ."\n\n";
echo "<br>";
} pg_close($conn);
?>
上一篇:配置Linux防火墙


下一篇:【ASP.NET】website转webapplication