是否有一种方法可以使堆栈跟踪在出现错误时显示整个生成的SQL语句,而不仅仅是前几个字符?
这是它目前显示的内容
...\Zend\Db\Adapter\Pdo\Abstract.php(220):Zend_Db_Adapter_Abstract-> query('UPDATE"diction ...',Array)
..我希望在发送到数据库之前看到整个更新语句,以跟踪它的错误.
谢谢您的帮助.SWK
Ivo*_*ert 12
如果要查看完整的sql语句,可以使用Zend_Debug.例如,如果您的sql语句位于变量$ select中,并且您想要查看完整的sql语句,则可以使用以下代码行:
Zend_Debug::Dump($select);
exit;
Run Code Online (Sandbox Code Playgroud)
或者,如果您的代码是使用Zend_Db_Table类创建的,则可以使用:
$select = new Zend_Db_Select(Zend_Registry::get('db'));
$select->from('string');
Zend_Debug::Dump($select->assemble());
exit;
Run Code Online (Sandbox Code Playgroud)
我认为查看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);
Run Code Online (Sandbox Code Playgroud)
firebug附加组件(firephp的要求)可以在这个网站上找到: Firebug
FirePHP插件可以在这个网站上找到: FirePHP
Ivo Trompert
| 归档时间: |
|
| 查看次数: |
7212 次 |
| 最近记录: |