根据 Rob 所说的,
我进去修改了 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 类中,我更改了所有
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 语句,而对性能的影响为零,这与分析器不同。