how do I delete rows in Yii?

Ionut Flavius Pogacian picture Ionut Flavius Pogacian · May 29, 2012 · Viewed 49.2k times · Source

Using Yii, I want to delete all the rows that are not from today.

Is my solution ok ?

$query = "delete from `user_login_hash` where `day`!='".(date('Y-m-d',time()))."'";

Yii::app()->db->createCommand($query);

Answer

adamors picture adamors · May 29, 2012

A prettier solution is

YourUserModel::model()->deleteAll("day !='" . date('Y-m-d') . "'");