How to make Doctrine_Expression (Doctrine 1.2) try to get the last 7 days

I am trying to make this request with doctrine 1.2:

$q->where('date > ?', new Doctrine_Expression('DATE_SUB(CURDATE() , INTERVAL 7 DAY)')); 

but he does not return me any results.

any idea?

thanks

+1
source share
1 answer

The reason it returns nothing is because Doctrine escapes the expression - generated SQL

 WHERE (date > 'DATE_SUB(CURDATE(), INTERVAL 7 DAY)') 

but not

 WHERE (l.action_time > DATE_SUB(CURDATE(), INTERVAL 7 DAY)) 

You can make it work as follows:

 $date = new Doctrine_Expression('DATE_SUB(CURDATE() , INTERVAL 7 DAY)'); $q->where('date > ' . $date); 

However, this is not the safest option, since the input is not shielded and is not good practice ...

+4
source

Source: https://habr.com/ru/post/912584/


All Articles