在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] . " "; echo "NAME = ". $row[1] ." "; echo "ADDRESS = ". $row[2] ." "; echo "SALARY = ".$row[4] ." "; echo "<br>"; } pg_close($conn); ?>