围绕什么罗布说基础,
我去和修改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