Zend 框架堆栈跟踪 [英] zend framework stack trace

查看:31
本文介绍了Zend 框架堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to make stack trace to display the whole generated SQL statement when there is an error instead just the first few characters of it?

这是它当前显示的内容

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

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

..我想在发送到数据库之前查看整个更新语句以跟踪它的问题.

..and I would like to see the whole update statement before sent to the db to track what is wrong with it.

感谢您的帮助.SWK

推荐答案

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

If you want to view the complete sql statement you can use Zend_Debug. For example if your sql statement is in the variable $select and you want to view the complete sql statement you can use the following line of code:

Zend_Debug::Dump($select);
exit;

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

Or if your code is created withe the Zend_Db_Table class you can use:

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

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

I think the best way to view the sql statement is by using the profiling function on the database connection. This is combination withe the logging function and the firePHP add-on for Firefox is my favorite setup.

如果你使用 Zend Framework 的 MVC 配置,这行代码就完成了:

If you use the MVC configuration of Zend Framework this is done white this lines of code:

// 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 的要求)可以在这个网站上找到:萤火虫

The firebug add-on (requirement for firephp) can be found on this website: Firebug

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

The FirePHP add-on can be found on this website: FirePHP

伊沃·特朗佩特

这篇关于Zend 框架堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆