php pgadmin 远程数据库连接失败

发布于 2024-10-19 03:25:09 字数 846 浏览 2 评论 0原文

我想从 php 连接到远程数据库到 postgres 但它无法连接并显示

 Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server:    
could not connect to server: No route to host (0x00002751/10065) Is the server running on host "xxxxxxxxx" and accepting TCP/IP connections on port 5432? in C:\xampp\htdocs\test.php on line 4
Wrong CONN_STRING

<html> 
    <body> 
        <?php 
        $db = pg_connect('host=xxx.xxx.xxx.xxx port=5432 dbname=postgres user=postgres password=') or die('Wrong CONN_STRING'); 
        if (!$db) {
                echo 'error';
            }else{
            echo 'success';
            }

        ?> 
    </body> 

我可以从 pgadmin 客户端访问同一个数据库,该客户端在运行 apache 的同一台机器上运行,我无法理解 pgadmin 可以访问数据库,但 apache web 服务器的 php 无法访问?有什么想法吗?

I want to connect to remote database from php to postgres but it could not connect and says

 Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server:    
could not connect to server: No route to host (0x00002751/10065) Is the server running on host "xxxxxxxxx" and accepting TCP/IP connections on port 5432? in C:\xampp\htdocs\test.php on line 4
Wrong CONN_STRING

<html> 
    <body> 
        <?php 
        $db = pg_connect('host=xxx.xxx.xxx.xxx port=5432 dbname=postgres user=postgres password=') or die('Wrong CONN_STRING'); 
        if (!$db) {
                echo 'error';
            }else{
            echo 'success';
            }

        ?> 
    </body> 

The same database I can access from pgadmin client which is running over same machine where apache is running, I could not understand that pgadmin can access db but apache webserver's php could not access ? any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-10-26 03:25:09

“没有到主机的路由”告诉您存在某种网络问题 - 不同的客户端能够从同一主机访问它的事实表明它是某种安全限制或防火墙阻止了连接,但是如果没有有关您的环境的详细信息,就很难更具体。

"No route to host" tells you that there is some kind of networking problem - the fact that a different client is able to access it from the same host would indicate it's some kind of security restriction or a firewall that is preventing the connection, but it's hard to be more specific without detailed information about your environment.

冰雪之触 2024-10-26 03:25:09

是SELinux的问题
以下命令修复了问题

setsebool -P httpd_can_network_connect=1

It was problem of SELinux
Following command fixed the problem

setsebool -P httpd_can_network_connect=1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文