how to make Doctrine_[removed] doctrine 1.2 ) try to get last 7 days

前端 未结 1 928
太阳男子
太阳男子 2021-01-24 19:56

I try to make this query with doctrine 1.2:

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


        
1条回答
  •  醉梦人生
    2021-01-24 20:22

    The reason why it doesn't return anything is because Doctrine escapes the expression - the generated SQL is

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

    rather than

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

    You could force it to work like this:

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

    This isn't the safest option however, as the input doesn't get escaped and isn't good practice...

    0 讨论(0)
提交回复
热议问题