젠드 프레임 워크를 사용하는 PHP 프로젝트에서 많은 mysql 서버와 많은 pdo_mysql 어댑터가 있습니다. 한 순간에 나는 예외 (Zend_Db_Statement_Exception)를 잡는 중이다. 어떤 어댑터가이 예외를 throw하는지 어떻게 결정할 수 있습니까?Zend_Db_Exception - 어댑터를 얻는 방법
2
A
답변
1
예외의 출처를 얻기 위해 Zend_Exceptions 클래스에는 아무것도 없지만 getTrace()
메서드가 있습니다. 이 getTrace을 사용하여 Zend_Db_Select 객체 객체를 가져올 수 있습니다. Zend Framework 버전이 너무 오래되어 있지 않으면 getAdapter 클래스가 있습니다 (Zend_Db_Select에 getAdapter가없는 경우 코드 작성 방법이 매우 어렵습니다.) $ this -> _ adapter가 존재하므로). 다음은 catch 섹션에서 어댑터 구성에 대한 세부 정보를 얻기 위해 사용할 수있는 코드입니다.
} 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
}