1

I have the following code:

$time = 60 * 60 * 24 * 3;

$usersTable = new Application_Model_Db_Users();

$where = 'active = false AND registration_time < ' . time() - $time;
$usersTable->delete($where);

But when it is run it deletes all the rows in the table, where as when I run

DELETE FROM users
WHERE active = false
AND registration_time < 1290500000

Only the ones that match the criteria are deleted. What is the problem?

moteutsch
  • 3,741
  • 3
  • 29
  • 35
  • can you confirm Zend_Db_Table evaluates to the same query as the query you show? Add a Zend_Db_Profiler to find out. Also, wouldn't it make more sense to calculate the interval in SQL instead of PHP. – Gordon Nov 25 '10 at 14:43

1 Answers1

3

You just need to wrap it with parenthesis, so that time() - $time evaluates properly.

$where = 'active = false AND registration_time < ' . (time() - $time);