title: Heroku PHP pgconnect - password authentication failed for user
body: <p>I'm trying to connect to PostgreSQL from PHP on Heroku. For simplification I tried:</p>
  
  <pre><code>function pg_connection_string_from_database_url() {
      extract(parse_url(getenv("DATABASE_URL")));
      return "user=$user password=$pass host=$host sslmode=require dbname=" . substr($path, 1);
  }
  $pg_conn = pg_connect(pg_connection_string_from_database_url());
  </code></pre>
  
  <p>I keep getting this error:</p>
  
  <pre><code>FATAL: password authentication failed for user
  </code></pre>
  
  <p>I've tried:</p>
  
  <ul>
  <li>Connecting with same credentials using Navicat: works</li>
  <li>Connecting to a local pgsql database using PHP: works</li>
  <li>Connecting with same credentials from CLI: works</li>
  </ul>
  
  <p>This makes me think there is something that PHP should do with the password. I found some things about MD5 online, but can't find anything specific.</p>
  
  <p>Any idea how to fix this?</p>