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 

official documentation link

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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -