zend框架堆栈跟踪

时间:2008-12-01 11:50:04

标签: zend-framework

有没有办法让堆栈跟踪在出现错误时显示整个生成的SQL语句而不只是前几个字符?

这是它目前显示的内容

  

... \ Zend \ Db \ Adapter \ Pdo \ Abstract.php(220):Zend_Db_Adapter_Abstract-> query('UPDATE“diction ...',Array)

..我希望在发送到数据库之前看到整个更新语句,以跟踪它的错误。

感谢您的帮助。 SWK

2 个答案:

答案 0 :(得分:12)

如果要查看完整的sql语句,可以使用Zend_Debug。例如,如果你的sql语句在变量$ select中,并且你想查看完整的sql语句,你可以使用以下代码行:

Zend_Debug::Dump($select);
exit;

或者,如果您的代码是使用Zend_Db_Table类创建的,则可以使用:

$select = new Zend_Db_Select(Zend_Registry::get('db'));
$select->from('string');
Zend_Debug::Dump($select->assemble());
exit;

我认为查看sql语句的最佳方法是使用数据库连接上的profiling函数。这是日志功能的组合,Firefox的firePHP插件是我最喜欢的设置。

如果你使用Zend Framework的MVC配置,那么这行代码是白色的:

// setup the database connection
$db = Zend_Db::factory(Zend_Registry::get('config')->database->adapter,Zend_Registry::get('config')->database->params);

// create a new profiler
profiler = new Zend_Db_Profiler_Firebug('All DB Queries');

// enable profiling (this is only recommended in development mode, disable this in production mode)
$profiler->setEnabled(true);
// add the profiler to the database object
$db->setProfiler($profiler);

// setup the default adapter to use for database communication
Zend_Db_Table_Abstract::setDefaultAdapter($db);

// register the database object to access it in other parts of the project
Zend_Registry::set('db',$db);

/**
*
* This part is optional
*
* You can use this logger to log debug information to the firephp add-on for Firefox
* This is handy for debugging but must be disabled in production mode
*
*/

// create logger
$logger = new Zend_Log();

// create firebug writer
$firebug_writer = new Zend_Log_Writer_Firebug();

// add writer to logger
$logger->addWriter($firebug_writer);

// register the logger object to access it in other parts of the project
Zend_Registry::set('log',$logger);

可以在本网站上找到firebug附加组件(firephp的要求): Firebug

FirePHP插件可以在这个网站上找到: FirePHP

Ivo Trompert

答案 1 :(得分:3)

虽然分析器是V很酷 - 当系统抛出异常时它无法调试..

查看这篇文章,提供更详细的堆栈跟踪inc full SQL

出于显而易见的原因,只能在DEV环境中使用

http://www.edmondscommerce.co.uk/blog/zend-framework/zend-framework-more-detailed-stack-trace/