* Run a Query With Return

$list= Yii::app()->db->createCommand('select * from post')->queryAll();
$rs=array();
foreach($list as $item)
{ //process each item here 
    $rs[]=$item['id']; 
}
return $rs;


* Bind some params

$list= Yii::app()->db->createCommand(
'select * from post where category=:category')->bindValue('category',$category)->queryAll();

Example :
$connection = yii::app()->db; 
$sql1 = "INSERT INTO interest (UserId, ItemId) VALUES(:usr, :itm)"; 
$command=$connection->createCommand($sql1); 
$command->bindValue(":usr", Yii::app()->user->id); 
$command->bindValue(":itm", $_GET['ItemId']); 
$command->execute();


* Run a Query without Return

Yii::app()->db->createCommand('delete * from post')->query();

 

Sumber : http://www.yiiframework.com/forum/index.php/topic/26617-how-to-run-sql-statement-in-yii/