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?

1
  • 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. Commented Nov 25, 2010 at 14:43

1 Answer 1

3

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

$where = 'active = false AND registration_time < ' . (time() - $time);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.