Query Execution


I have doubt in query execution please help me how to execute this ‘SELECT columnname from tablename’ in yii using cdbcriteria.

criteria means you will have to filter something or order

// 1 simple query

$r = Yii::app()->getDb()->createCommand("SELECT columnname FROM tablename")->queryAll();

// 2 criteria in active record

$c = new CDbCriteria();

$c->select = ['columnname'];

$r = Books::model()->findAll($c);

where Books active record model corresponds to tablename table.

// 3 criteria with data provider and active record

$c = new CDbCriteria();

$c->select = ['columnname'];

$dp = new CActiveDataProvider('Books');


$r = $dp->getData();