2011-02-24 39 views
1

我想从php连接到远程数据库postgres,但它无法连接并说PHP pgAdmin的远程数据库连接失败

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无法访问?任何想法 ?

+0

我也试过,但不工作 http://www.ehow.com/how_2090983_connect-remote -database-下selinux.html – 2011-02-24 07:29:11

回答

0

这是SELinux的 的问题下面的命令解决了这一问题

setsebool -P httpd_can_network_connect = 1

0

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