yii query

MY query is:-

$sql = "SELECT * FROM backup_history WHERE DATE_FORMAT(datetime, ‘%Y-%m-%d’ ) = ‘$current_date’ AND site_id=’$data[site_id]’ ";

How can I convert this query to run in Yii?

does anyone solve it problem.


you can use various way to execute custom query ,

just create a function in your model…

public function functionName(){

		$data = Yii::app()->db->createCommand()




		return $data;			



$sql="Select * .... ....";




$sql="Select * .... ....";


return $command;


I want convert my query in yii format.

There are many ways for this… one shown below,

$criteria = new CDbCriteria();

$criteria->select = array('price','shipping','stock');

$criteria->condition = "productId = $productId";

$result=Product::model()->find($criteria); // find/findAll  depends