I am assuming you are running this locally, so check that display_errors
is enabled in your local php.ini
and that error_reporting
is set to something reasonable. That would be the reason you're not getting error output.
You should then see that either the connection is refused for some reason (could be your network), or that e.g. your local PHP doesn't have OpenSSL enabled (globally or for Postgres).
If this is happening on Heroku, then you'll never see errors in the page because it's a production env where display_errors
should never be on; run heroku logs
to see what PHP says. In this case the only reason would be that your credentials are incorrect, so check them for typos.
Which brings me to some important advice: do not hard-code these credentials (or any other config) in your code. Heroku gives you a DATABASE_URL
env var with the connection string; read from that dynamically by using what parse_url(getenv('DATABASE_URL'))
gives you. The reason is that your credentials may change in case Heroku needs to do an automatic failover of your database, and if you hard-code these credentials, your app would go down in this case.
If this is on Heroku, you really should run this stuff locally properly, that means with a local Postgres database as well, instead of connecting remotely to production databases, or even blindly pushing up your code to Heroku all the time without trying it locally. Much easier and faster over time.