Can#39;t Connect to PostgreSQL with PHP pg_connect()(无法使用 PHP pg_connect() 连接到 PostgreSQL)
问题描述
我刚刚意识到这个问题可能更适合 ServerFault.版主不要复制它,请把它移过来?谢谢.
I just realized that this question may be better suited to ServerFault. Instead of copying it, a moderator please move it over? Thanks.
我检查了 php-info,并且 Postgresql 扩展在那里(pg_connect()
不是未定义的).我还可以使用本地主机上的 psql
连接到 postgresql(我已经适当地编辑了我的 pg_hba.conf 文件).这是不起作用的代码:
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.
我检查了我的 apache 日志,这是相关的错误消息:
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
Is the server running on host "localhost" and accepting
TCP/IP
connections on port 5432?
如何修复/调试此问题?
How can I fix/debug this?
我在 Centos 5.4 顺便说一句.
I'm on Centos 5.4 btw.
推荐答案
无法连接到服务器:权限被拒绝
could not connect to server: Permission denied
我在 Centos 5.4 顺便说一句.
I'm on Centos 5.4 btw.
检查 /var/log/audit/audit.log
.您可能遇到了 SELinux 规则.
Check /var/log/audit/audit.log
. Chances are that you're hitting a SELinux rule.
这篇关于无法使用 PHP pg_connect() 连接到 PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用 PHP pg_connect() 连接到 PostgreSQL


基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01