从ZendFramework获取完整的堆栈跟踪

时间:2012-12-27 11:02:02

标签: mysql zend-framework php

我有一个非常大的Web应用程序,它使用ZendFramework。在某些SQL语句中似乎存在语法错误(很多东西是自动生成的),但是记录的错误非常无用(删除了项目信息)

Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near [...] in [...]/ZendFramework/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 [...]/ZendFramework/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 [...]/ZendFramework/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#2 [...]/ZendFramework/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 [...]/ZendFramework/Zend/Db/Adapter/ in [...]/ZendFramework/Zend/Db/Statement/Pdo.php on line 234

此堆栈跟踪仅包含Zend Framework内部的引用,而实际的调用者(语法错误最有可能出现的地方)无处可见。

如果发生错误,如何让Zend Framework为我提供完整的堆栈跟踪?

2 个答案:

答案 0 :(得分:2)

这些异常应该由您的ErrorController()或任何您作为ErrorController 传递的内容)记录,通常在默认模块中记录( application / controllers / ErrorController.php )。如果是这种情况,更改日志记录机制应该非常简单。

可能需要一些实验来确定您需要使用哪些Exception()方法来获得所需的输出。

<强> [编辑]

我应该注意到,如果您使用默认错误设置,视图将是更新的简单位置:

<!-- application/views/scripts/error/error.phtml -->
<html>
    <body>
        <h1>An error occurred</h1>
        <h2><?php echo $this->message ?></h2>
        <?php if (isset($this->exception)): ?>
            <h3>Exception information:</h3>
            <p>
                <b>Message:</b> <?php echo $this->exception->getMessage() ?>
            </p>
            <h3>Stack trace:</h3>
            <pre><?php echo $this->exception->getTraceAsString() ?>
            <!-- add full Trace info -->
            <pre><?php echo $this->exception->getTrace() ?></pre>
            </pre>
            <h3>Request Parameters:</h3>
            <pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?>
            </pre>
        <?php endif ?>
    </body>
</html>

答案 1 :(得分:1)

如果您需要更详细的堆栈跟踪,可以使用:

foreach($this->exception->getTrace() as $t){
        var_dump($t);
    }

提到了here。但我认为你最好使用firebug和firephp并使用Zend_Debug_Profiler_Firebug类调试sql查询,如本篇有用的文章hereherehere所述。