通过远程 IP 地址连接到 PostgreSQL 数据库,我已经通过 Windows 使用 pgAdmin III 成功,但是每当我尝试使用标准php-pgsql
库从本地 CentOS 6 Apache Web 服务器使用pg_connect()
.
笔记:
- 我无法控制远程服务器,但如果需要可以查询其他信息。
- 我的密码确实包含一个特殊字符(尽管它不是引号字符)。
信用如下:
Host (IP): xx.xx.xx.xx
Port: 5432
DBname: sandbox
Username: abc
Password: ***
MaintenanceDB: template1
这是我尝试在本地服务器上运行的 PHP 代码:
pg_connect("host=xx.xx.xx.xx port=5432 dbname=sandbox user=abc password=***");
我也试过:
pg_connect("host=xx.xx.xx.xx port=5432 dbname=template1 user=abc password=***");
当我尝试连接时,我收到以下错误:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "xx.xx.xx.xx" and accepting TCP/IP connections on port 5432?
我已extension=pgsql.so
在/etc/php.d/
目录中添加/取消注释,并且service httpd restart
. 我什至已经打开了我的iptables
端口,所以毫无疑问本地防火墙端口被阻止:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 5432 -j ACCEPT
提前致谢 :-)