php - Yii2 db getStats (db queries number) -
there 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
is there method in yii2 information?
here equivalent yii 2:
$profiling = yii::getlogger()->getdbprofiling();
$profiling[0]
contains total count of db queries, $profiling[1]
- total execution time.
note if want information all queries @ end of request should execute code in right place, example in afteraction()
:
public function afteraction($action, $result) { $result = parent::afteraction($action, $result); $profiling = yii::getlogger()->getdbprofiling(); ... return $result; }
otherwise information according moment of execution command.
official documentation:
Comments
Post a Comment