How to get last executed query in Yii2?

Are you wanted to get last executed sql query in yii2, we can use:

$query = new Country::find()->where('id=1');
echo $query->createCommand()->sql;

or to get the SQL with all parameters included try:

$query->createCommand()->getRawSql()

 

Add a Comment

Your email address will not be published. Required fields are marked *