1. 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

Discussion in 'XenForo Development Discussions' started by Rayman, Sep 7, 2016.

  1. Rayman

    Rayman Member

    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?


    $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!'); }​

    SQLSTATE[HY000] [1045] Access denied for user ....​
  2. Pierce

    Pierce Well-Known Member

  3. Mike

    Mike XenForo Developer Staff Member

    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().

Share This Page