1

我正在尝试连接到 Heroku 上我的应用程序的 PostgreSQL 数据库:

$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”、数据库“dbname”没有 pg_hba.conf 条目,D 中 SSL 关闭: \wamp\www\heroku_app\test.php 在第 53 行

这里有什么问题?我该如何解决?

注意:这只发生在我在本地机器上运行时(通过 WAMP 服务器)。如果我将它部署到 Heroku,那么它运行良好

4

3 回答 3

3

这里的关键错误是SSL off. Heroku Postgres 需要 SSL 进行外部连接。确保您的 PHP 使用 SSL 编译并在您的连接中指定它sslmode=require

于 2013-05-03T04:47:54.040 回答
0

添加“sslmode=require;” 到您的连接字符串。

于 2013-11-10T21:18:50.863 回答
0

查看此快速提示以获取更多帮助,但简而言之,您可以使用以下方式获取您的凭据:

heroku pg:credentials COLOR

...其中 COLOR 是以下返回值的一部分:

heroku addons:add heroku-postgresql

它兼作将 postgres 添加到您的应用程序的命令

于 2013-05-03T04:21:24.837 回答