title: PHP connection to PostgreSQL, FATAL: password authentication failed for user
body: <p>I am new to postgreSQL and web development and lately I tried to connect my previously created database via PHP. But things didn't worked out, I get the password authentication failed for the user postgres. I've been looking everywhere but can't find anything to solve this issue.</p>
  
  <p>The database is hosted on my iMac, port 5432 and php script on heliohost.org which will be used later on to query the database. </p>
  
  <p>Here is my php script:</p>
  
  <pre><code>&lt;?php 
  $host        = "host=127.0.0.1";
  $port        = "port=5432";
  $dbname      = "dbname=osm";
  $credentials = "user=postgres password=newPassword";
  
  $db = pg_connect( "$host $port $dbname $credentials"  ); 
  
  if(!$db){
    echo "Error : Unable to open database\n";
  } else {
    echo "Opened database successfully\n";
  } 
  ?&gt;
  </code></pre>
  
  <p>My pg_hba.conf looks like this :</p>
  
  <p>local   all   postgres   md5</p>
  
  <p>and my postgresql.conf has : listen_addresses = localhost</p>
  
  <p>I am a bit confused with this, if anyone have suggestion to get this up and running.</p>
  
  <p>Thanks everyone!</p>