【问题标题】:How can I connect to a postgres database in WebMatrix php?如何在 WebMatrix php 中连接到 postgres 数据库?
【发布时间】:2014-01-05 02:57:27
【问题描述】:

我不太确定如何通过 WebMatrix 创建的本地服务器连接到 heroku 上的数据库。如果我的应用程序托管在 heroku 上时运行 php 脚本,我有代码可以连接到数据库工作。以下行失败:

$dbconn = pg_connect("host=someEC2Instance.com port=5432 dbname=xxxxxxx user=xxxxxxxx password=xxxxxxxxxx sslmode=require options='--client_encoding=UTF8'") or die('Could not connect: ' . pg_last_error());

我想使用托管在 heroku 上的数据库,有人知道这里出了什么问题吗?

【问题讨论】:

    标签: php postgresql heroku webmatrix


    【解决方案1】:

    通常数据库未配置为“外部”访问。我不太了解主机 Heroku,但是:我会说您无法使用您的网络服务器“从外部”访问数据库。

    你能发布完整的错误信息吗?

    你可以回显“pg_last_error”。我敢打赌它会说“连接被拒绝”或“连接超时”。

    要访问数据库,您应该在 heroku 上托管 WebApplication 或在您的电脑上本地安装数据库。

    您好。

    【讨论】:

    • Heroku 不是这种情况——它们允许直接的数据库连接。
    • pg_connect执行后没有一行,所以无法输出pg_last_error
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    相关资源
    最近更新 更多