无法用PHP连接到PostgreSQL pg_connect() [英] Can't Connect to PostgreSQL with PHP pg_connect()
问题描述
编辑:我只是意识到这个问题可能更适合ServerFault。而不是复制它,主持人请移动它?谢谢。
我已经检查过php-info,Postgresql的扩展名是( pg_connect()
未定义)。我也可以连接到postgresql使用 psql
在localhost(我已经适当地编辑了我的pg_hba.conf文件)。这里的代码不工作:
<?php
$ dbconn = pg_connect(host = localhost port = 5432 dbname = mydb user = myuser password = mypass)或die('Could not connect:'。pg_last_error());
?>
此代码只会导致浏览器中显示Could not connect:
我检查了我的apache日志,这里是相关的错误消息:
:pg_connect()[< a href ='function.pg-connect'> function.pg-connect< / a>]:
无法连接到PostgreSQL服务器:无法连接到服务器:权限
denied\\\
\t运行在主机& quot; localhost& quot;上的服务器。并接受端口5432上的\\\
\tTCP / IP
连接?
如何修复/调试这个?
编辑:我在Centos 5.4 btw。
无法连接到服务器:权限被拒绝
编辑:我在Centos 5.4 btw。
检查 /var/log/audit/audit.log
。很可能是你正在击中SELinux规则。
EDIT: I just realized that this question may be better suited to ServerFault. Instead of copying it, a moderator please move it over? Thanks.
I've checked php-info, and the Postgresql extension is there (pg_connect()
is not undefined). I am also able to connect to postgresql using psql
on localhost (I've edited my pg_hba.conf file appropriately). Here is the code that's not working:
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=myuser password=mypass") or die('Could not connect: ' . pg_last_error());
?>
This code simply results in "Could not connect: " being displayed in the browser.
I checked my apache log, and here's the relevant error message:
PHP Warning: pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]:
Unable to connect to PostgreSQL server: could not connect to server: Permission
denied\n\tIs the server running on host "localhost" and accepting\n\tTCP/IP
connections on port 5432?
How can I fix/debug this?
Edit: I'm on Centos 5.4 btw.
could not connect to server: Permission denied
Edit: I'm on Centos 5.4 btw.
Check /var/log/audit/audit.log
. Chances are that you're hitting a SELinux rule.
这篇关于无法用PHP连接到PostgreSQL pg_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!