I have a table "backup_history" which store sites backup details in my database with the following fields:
id
site_id
backup_file_name
file_size
by (cron/manual)
datetime
For the next backup, I need to find out recent last backup date n time of the site and compare with the settings(daily backup) and run next backup by cron.
But am unable to find out last inserted row with the
site_id = $id AND by = 'cron' AND datetime = 'this will be recent date-time'
$lastbackup = BackupHistory::model()->findByAttributes(array('site_id' => $single_site->id, 'by' => 'cron'));
This code provides a row but not with recent date n time.
May be am going wrong so plz suggest some solution. Thanks !!!
You'll need to order by
your result. So try this:
$lastbackup = BackupHistory::model()->findByAttributes(array('site_id' => $single_site->id, 'by' => 'cron'),array('order'=>'datetime'));