using DAO

hi!! i want to use DAO in ma project. i went trhrough the documentation. but didnt understand where to use it. can anyone show me a simple example?? it’ll be of great help…please. try to find time…


I think that your doubt is most related to “where” to use the DAO code. It depends on what you want to do with DAO. You can use it inside a controller to fetch data via ->queryAll() or to execute commands that don’t return rows, like DELETE, UPDATE, etc

this is a very simple code I use inside my Offer model class to clean up expired offers, hope this can help you

note that i’m not using error handling, this is only for you to have an idea, ok?

	public function clearExpiredHighlights($companyId=null){

		//clean up old site highlights

		if (0 < $companyId):

			$sql = 'UPDATE Offer

				set offerHighlight = 0

				WHERE offerHighlight = 1

				AND CURDATE() > offerDateFinish

				AND companyId =:cpid;';

			$connection = Yii::app()->db;

			$command = $connection->createCommand($sql);





Hi scoob.junior or someone else,

Can i see an full example with controller and view using DAO plz.

I have some difficults with this.

Best regards, thx.