pg_connect() is showing the error in table format.Instead of showing error message as table format need a error message alert.
Error Message
Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: password authentication failed for user "test" in /home/test/public_html/QueueManager/Modules/Database.php on line 41
After if showing error as table format.
After executing pg_connect() throwed exception.
But is is not working.
Code
function connect()
{
  $HOST = $GLOBALS[Database_Conn][Db_Host];     # Host name 
  $USER = $GLOBALS[Database_Conn][Db_User];     # database user name 
  $DBNAME = $GLOBALS[Database_Conn][Db_Name];   # name of the database
  $PASSWORD = $GLOBALS[Database_Conn][Db_Pass]; # password the database user.
  try 
  {
    $conn = pg_connect("host=$HOST dbname=$DBNAME user=$USER ".
                       "password=$PASSWORD sslmode=disable");
    if(!$conn)
    {
      throw new Exception("Database Connection Error");
    }
    return $conn;
  }
  catch (Exception $e) 
  {
    print <<<_HTML_
    <script> alert('Caught exception'); 
    </script> _HTML_;
    die();
  }
}
Please give me the solution
pg_connect does not throw exception, so you have to translate to exception like below.
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
try {
    $conn=@pg_connect("host=dbhost user=dbuser dbname=db password=dbpass");
} Catch (Exception $e) {
    Echo $e->getMessage();
}
Please refer this more detail
http://php.net/manual/en/language.exceptions.php
To hide the error text generated by PHP, add @ in front of the function call, e.g.:
$conn = @pg_connect("host=$HOST dbname=$DBNAME user=$USER ".
                   "password=$PASSWORD sslmode=disable");
More details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With