• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

If mysql connection is successful

#1
I need to check if a mysql connection has been successful, otherwise return something else instead of it spitting out an error message (see error message below). Is there any way to do this?

Connection

$db3 = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => 'xxx',
'username' => 'xxx',
'password' => 'xxx',
'dbname' => 'xxx'
));

I have tried
if(!$db3->getConnection()) { return $this->responseError('No no no!'); }​

Error
SQLSTATE[HY000] [1045] Access denied for user ....​
 

Mike

XenForo developer
Staff member
#3
You will want to wrap your getConnection() line in a try-catch (catching Zend_Db_Exception). If you catch an exception, it failed. You can see an example in XenForo_Install_Controller_Instal::_testConfig().