1

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 !!!

Frank
  • 2,285
  • 7
  • 43
  • 68

1 Answers1

5

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'));
bool.dev
  • 17,508
  • 5
  • 69
  • 93