dqwh0109 2015-03-17 08:46
浏览 54
已采纳

Yii2 db getStats(db查询号)

There is useful method getStats in Db-component Yii

$sql_stats = YII::app()->db->getStats();
echo $sql_stats[0] //the number of SQL statements executed
echo $sql_stats[1] //total time spent

Official documentation link

Is there method in Yii2 to get this information?

  • 写回答

2条回答 默认 最新

  • dongliao3450 2015-03-17 10:28
    关注

    Here is equivalent for Yii 2:

    $profiling = Yii::getLogger()->getDbProfiling();
    

    $profiling[0] contains total count of DB queries, $profiling[1] - total execution time.

    Note that if you want to get information about all queries at the end of request you should execute this code in right place, for example in afterAction():

    public function afterAction($action, $result)
    {
        $result = parent::afterAction($action, $result);
    
        $profiling = Yii::getLogger()->getDbProfiling();
    
        ...
    
        return $result;
    }
    

    Otherwise you will get the information according to the moment of execution this command.

    Official documentation:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示