如何从PHP中的本地连接连接到Heroku Postgres数据库 [英] How to connect to Heroku postgres database from a local connection in php

查看:76
本文介绍了如何从PHP中的本地连接连接到Heroku Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从本地运行的php代码访问我的Heroku Postgres数据库.

I'm trying to access to my Heroku Postgres database from a php code that runs locally.

pg_connect("host=myhost port=5432 dbname=mydb user=me password=*** sslmode=require options='--client_encoding=UTF8'")

当代码在Heroku而非本地运行时,

效果很好. (该值是Heroku给出的值)

works well when the code runs on Heroku, but not locally. (the value are those given by Heroku)

我收到此错误:

无法连接到PostgreSQL服务器:sslmode值"require" 当未编译SSL支持时无效

Unable to connect to PostgreSQL server: sslmode value "require" invalid when SSL support is not compiled in

如果删除sslmode,则会出现此错误:

If I delete sslmode, I get this error :

网络不可达服务器是否在主机"myhost"上运行并且 在端口5432上接受TCP/IP连接?

Network is unreachable Is the server running on host "myhost" and accepting TCP/IP connections on port 5432?

有人有线索吗?这会很有帮助!

Does someone has a clue ? It would help a lot !

推荐答案

Heroku Postgres要求使用sslmode进行外部连接.您可能需要使用--with-openssl[=dir]编译标志来编译PHP.请参阅此处以获取更多信息: http://www.php.net/manual/zh-CN /book.openssl.php

Heroku Postgres requires sslmode for external connections. You likely need to compile PHP with the --with-openssl[=dir] compile flag. See here for more information: http://www.php.net/manual/en/book.openssl.php

您能验证您的PHP安装中已编译了openssl吗?我知道要检查的唯一方法是使用phpinfo()页并查找--with-openssl标志.

Can you verify your installation of PHP has openssl compiled in with it? The only way I know to check this is with a phpinfo() page and look for the --with-openssl flag.

这篇关于如何从PHP中的本地连接连接到Heroku Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆