2

In my project on PHP with Zend Framework i have many mysql servers and many pdo_mysql adapters. In one moment i'm catching exception (Zend_Db_Statement_Exception). How i can to determinate which adapter throws this exception ?

1 Answer 1

1

There's nothing in Zend_Exceptions classes to get the origin of the Exception, but the the getTrace() method. You can use this getTrace to get the Zend_Db_Select object object, and if your version of Zend Framework is not too old you have the getAdapter class on it (if you do not have the getAdapter on Zend_Db_Select it's not a very hard to code method, as $this->_adapter is present). So here is a code which can be used on the catch section to get details on the adapter configuration:

} catch (Exception $e) {
    foreach($e->getTrace() as $trace) {
        if($trace['class']=='Zend_Db_Adapter_Abstract' || 'Zend_Db_Adapter_Pdo_Abstract'==$trace['class']) {
            $zendDbSelect = $trace['args'][0];
            $zendDbAdapter = $zendDbSelect->getAdapter();
            $conn = $zendDbAdapter->getConfig();
            //output adapter configuration, more useful things could be done
            // with that if you want
            Zend_Debug::dump($conn);
            // stop the loop on traces
            break;
        }
    }
    // to something else with the exception if you want
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.