Blog Image

How to get raw sql query in yii or yii2 framework

If you have used the query builder in yii 2.0.8 framework then to get the raw sql generated use the below statement.

$query->andFilterWhere([‘like’, ‘username’, $this->username])
->andFilterWhere([‘like’, ’email_id’, $this->email])
->andFilterWhere([‘registration_date’ => $this->register_date]);
// This is echo the raw query generated
var_dump($query->createCommand()->getRawSql());



Author: admin

Vinod Ram has been in Software Industry since 2006 and has experience of over 16 years in Software Development & Project Management domain specialised majorly in LAMP stack & Open Source Technology, building enterprise level Web based Application, Large Database driven and huge traffic Websites and Project Management. He loves to write information articles and blog to share his knowledge and experience with the outside world and help people to find solution for their problems.