0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

not the case with Heroku - they allow direct database connections.
No line after pg_connect execute, so I can't output pg_last_error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.