一、更换yum原
# yum install epel-release
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
二、安装php PostgreSQL扩展
# yum install php72w-pgsql
三、vi pg_hba.conf: # IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
四、编写测试脚本 pgconn.php
<?php
$connStr = "host=localhost port=5432 dbname=postgres user=postgres password=password";
//simple check
$conn = pg_connect($connStr);
$result = pg_query($conn, "select * from pg_stat_activity");
print_r(pg_fetch_all($result));
?>
五、测试/usr/bin/php pgconn.php
六、reboot
七、浏览器访问pgconn.php
本文详细介绍如何通过更换YUM源并安装必要的PHP扩展来实现PHP与PostgreSQL数据库的连接。包括配置VIPg_hba.conf文件允许本地连接,编写及运行测试脚本来验证连接是否成功。
755

被折叠的 条评论
为什么被折叠?



