2012-12-27 171 views
1

我有一個非常大的使用ZendFramework的Web應用程序。似乎有一些SQL語句中的語法錯誤的地方(自動生成了很多東西),但記錄的錯誤是非常無益的(項目信息已刪除)從ZendFramework獲取完整堆棧跟蹤

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內只引用框架和實際的調用者(最可能出現語法錯誤的地方)無處可見。

我如何Zend框架給我的時候發生錯誤的一個完整的堆棧跟蹤?

回答

2

這些異常應該被記錄在您的ErrorController()或任何你有傳遞作爲ErrorController)通常默認模塊(應用/控制器/ ErrorController.php)。如果是這種情況,應該很簡單地修改記錄機制。

它可能只是需要一點實驗來找出你需要使用哪種方法來獲得你需要的輸出。

[編輯]

我應該指出的是,鑑於將是簡單的地方,如果你使用的是默認的錯誤設置更新:

<!-- 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

如果您需要更詳細的堆棧跟蹤,你可以使用:

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

提到here。但是,我想你會更好地使用螢火蟲和firephp和調試SQL查詢與Zend_Debug_Profiler_Firebug類,如本有用的文章hereherehere描述。

+0

獲取完整的堆棧跟蹤那樣是在很好,如果我知道拋出異常的位置,所以我可以將它包裝到try-catch塊中。但是,錯誤以「未捕獲的異常」開頭,所以我不知道異常處在哪裏,這就是爲什麼我要問這個問題。感謝您的鏈接,我會考慮他們的下一個應用程序,但在這一點上添加第三方工具幾乎是不可能的。 –

相關問題