2
votes

I have a connection to a data base and every time there is a problem connecting I get this error.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '205.178.146.104' (4)' in /data/18/2/77/115/2566441/user/2813515/htdocs/ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php:129 
Stack trace: 
#0 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:dbname=si...', 'xxx', 'xxx', Array) 
#1 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() 
#2 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Abstract.php(459): Zend_Db_Adapter_Pdo_Mysql->_connect() 
#3 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `user`', Array) 
#4 .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Mysq in .../ZendFramework-1.11.5/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144

The thing is that the database user and password are visible on the page in the error message. Is there a way that I can prevent PHP from showing that info? Or is this happening because I am set up a a developing instead of production?

2

2 Answers

2
votes

It is a combination of both. In development, your showing your errors. Which is the primary reason your seeing that.

However, you can catch the exception by testing the connection before the query. Allowing you to handle your own connection failures.

try {
    Zend_Db_Table::getDefaultAdapter()->getConnection();
} catch (Zend_Exception $e) {
    throw new Zend_Exception("A different error");
}
1
votes

It is because you are on "developing" (exceptions are shown in browser)

  • Solution 1: Use Production Environment ;)
  • Solution 2: Change settings in application.ini
  • Solution 3: Use an try/catch block for database connect