圍繞什麼羅布說基礎,
我去和修改Zend_Db_Exception類。並補充
public $_stmt = null;
然後在Zend_Db_Statement_Exception類我改變了__construct這樣:
/**
* @param string $message
* @param string|int $code
* @param Exception $chainedException
* @param Statment i.e. Query String
*/
public function __construct($message = null, $code = null, Exception $chainedException=null, $_stmt = null)
{
$this->message = $message;
$this->code = $code;
$this->_chainedException = $chainedException;
$this->_stmt = $_stmt;
}
在Zend_Db_Statement_Pdo I類變更
然後所有的
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
到
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e, $this->_stmt);
然後在我的Zend_Controller_Plugin_ErrorHandler動作中,我有這個引導它。
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case "EXCEPTION_NO_ROUTE":
case "EXCEPTION_NO_CONTROLLER":
case "EXCEPTION_NO_ACTION":
// 404 error -- controller or action not found
$this->view->title = "Page Not Found";
break;
default:
$this->view->title = "Unknown Error";
break;
}
$sql = null;
$offending_query = null;
$exception = $errors->exception;
try
{
$offending_query = $exception->_stmt->queryString;
}
catch (Zend_Exception $e)
{ }
隨着這一變化給了Zend DB核心我現在能夠捕捉零影響性能分析器不同一切都是我的問題的SQL語句。
以前的異常沒有工作,但Zend_Db_Profiler確實工作,雖然它造成了問題。它在某些部分將系統減速了5秒到1分鐘。所以我必須禁用分析器。 – Pyromanci 2012-04-18 19:44:03
我很驚訝,它讓你感覺很慢,因爲它沒有做太多!但是,在那種情況下,你只剩下猴子補丁的Zend_DB代碼。找到調用異常的代碼行,並在該位置添加一個日誌,以便在該特定代碼段的上下文中存儲任何可以存儲的內容。 – 2012-04-19 04:57:06