无法连接到PostgreSQL服务器 [英] Unable to connect to PostgreSQL server
问题描述
我正在尝试连接到Heroku上我的应用程序的PostgreSQL数据库:
I'm trying to connect to the PostgreSQL database of my app on Heroku:
$host = "ec2-54-235-242-31.compute-1.amazonaws.com";
$username = "user";
$password = "pass";
$database = "dbname";
$port = "5432";
$dbconn = pg_connect("host=".$host." port=".$port
." dbname=".$database." user=".$username." password=".$password)
or die('Could not connect: ' . pg_last_error());
但我遇到此错误:
警告:pg_connect()[function.pg-connect]:无法连接到PostgreSQL服务器:严重:主机 69.196.177.196,用户 user,数据库没有pg_hba.conf条目 dbname,第53行的D:\wamp\www\heroku_app\test.php中的SSL关闭
Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "69.196.177.196", user "user", database "dbname", SSL off in D:\wamp\www\heroku_app\test.php on line 53
这是问题吗?我该如何解决?
What is the problem here? How can I fix it?
注意:仅当我在本地计算机上运行时(通过WAMP服务器),这种情况才会发生。如果我将其部署到Heroku,那么它将运行正常
Note: this only happens when I run on my local machine (via WAMP server). If I deploy it to Heroku then it runs fine
推荐答案
此处的关键错误是 SSL关闭
。 Heroku Postgres需要SSL进行外部连接。确保您的PHP使用SSL编译,并在您的连接中指定 sslmode = require
。
The key error here is SSL off
. Heroku Postgres requires SSL for external connections. Make sure your PHP was compiled with SSL and specify it in your connection sslmode=require
.
- Heroku Postgres: External connections (ingress)
这篇关于无法连接到PostgreSQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!