php pgadmin 远程数据库连接失败
我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“没有到主机的路由”告诉您存在某种网络问题 - 不同的客户端能够从同一主机访问它的事实表明它是某种安全限制或防火墙阻止了连接,但是如果没有有关您的环境的详细信息,就很难更具体。
"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.
是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