2012-10-09 102 views
0

我正在寻找一种方法来配置由Zend_Table在内部执行的查询。
例如,完成快速入门课程后,如何配置所有执行的查询?
我试图实现从的application.ini这样的探查:是否可以配置Zend_Table查询?

resources.db.profiler.class = "Zend_Db_Profiler_Firebug" 
resources.db.profiler.enabled = true 

,并放置在留言控制器下一行:

... 
$db = Zend_Db_Table_Abstract::getDefaultAdapter(); 
$profiler = $db->getProfiler(); 

echo $profiler->getTotalElapsedSecs(); 

这给了我0

我已经也尝试启用Profiler在如下所示的Bootstrap文件中:

protected function _initProfiler() { 
    $this->bootstrap("db"); 
    $profiler = new Zend_Db_Profiler_Firebug("All DB Queries"); 
    $profiler->setEnabled(true); 
    Zend_Registry::get("db")->setProfiler($profiler); 
} 

Whick不给我任何结果(我已经使用Zend_Log_Writer_Firebug()安装并测试了Firebug和FirePHP)

我会很感激任何帮助。谢谢 !

回答

1

问题出在参数实例化中。当我输入

resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug" 
resources.db.params.profiler.enabled = true 

而不是以前的配置,一切都很顺利。 注意.params部分的参数行

+0

.params不适用于我,我改用resources.db.profiler = true resources.db.profiler.class =“Zend_Db_Profiler_Firebug” – max4ever

2

我还没试过Firebug分析器。但我确实使用了一个html表格输出分析器信息在查询的每个页面的底部。

启用的application.ini

resources.db.params.profiler = true 

探查呈现在布局轮廓结果:

<?php 
    $this->addScriptPath(APPLICATION_PATH . '/views/scripts'); 
    echo $this->render('profiler.phtml') 
?> 

profiler.phtml视图渲染

<?php 
// get the default db adapter 
$adapter = Zend_Db_Table::getDefaultAdapter(); 
$profiler = $adapter->getProfiler(); 
if ($profiler->getEnabled() && $profiler->getTotalNumQueries() > 0) : 
?> 
    <div style='text-align:center'> 
     <h2>Database Profiling Report</h2> 
     <p>Total queries executed: <?php echo $profiler->getTotalNumQueries() ?></p> 
     <p>Total elapsed time: <?php echo $profiler->getTotalElapsedSecs() ?></p> 
    </div> 
    <table class='spreadsheet' cellpadding='0' cellspacing='0' style='margin:10px auto'> 
     <thead> 
      <tr> 
       <th>#</th> 
       <th>Query</th> 
       <th>Time</th> 
      </tr> 
     </thead> 
     <tbody> 
    <?php foreach ($profiler->getQueryProfiles() as $queryNumber => $query) : ?> 
       <tr> 
        <td>(<?php echo $queryNumber + 1 ?>)</td> 
        <td><?php echo $query->getQuery(); ?></td> 
        <td><?php echo $query->getElapsedSecs(); ?></td> 
       </tr> 
    <?php endforeach ?> 
     </tbody> 
    </table> 
    <?php endif ?> 

我不想象使用萤火虫探查器要困难得多。

+0

这并不是我所期待的。不过谢谢! –