Matan Vardi
Matan Vardi

Reputation: 1

How can I connect to a postgres database in WebMatrix php?

I'm not exactly sure, how I can connect to a database I have on heroku through my local server created by WebMatrix. I have code to connect to the database work if I run the php script when my application is hosted on heroku. The line below fails:

$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());

I want to work with the database hosted on heroku, does anybody know what's wrong here?

Upvotes: 0

Views: 517

Answers (1)

Ralph D.
Ralph D.

Reputation: 31

Normaly databases are not configured for "external" access. I dont know the hoster heroku very well but: I would say you can't access the database "from external" with your webserver.

Could you post the complete error message?

You could echo the "pg_last_error".. I bet it says something like "connection refused" or "connection timed out".

To access the database you should host the WebApplication on heroku OR install the database local on your pc.

Greetings.

Upvotes: 1

Related Questions