Complex WHERE clauses using the PHP Doctrine ORM

后端 未结 7 1926
长发绾君心
长发绾君心 2020-12-13 09:15

I\'m using the PHP Doctrine ORM to build my queries. However, I can\'t quite seem to figure how to write the following WHERE clause using DQL (Doctrine Query Language):

7条回答
  •  旧巷少年郎
    2020-12-13 10:00

    From my experience, each complex where function is grouped within parenthesis (I'm using Doctrine 1.2.1).

    $q->where('name = ?', 'ABC')
      ->andWhere('category1 = ? OR category2 = ? OR category3 = ?', array('X', 'X', 'X'))
      ->andWhere('price < ?', 10)
    

    produces the following SQL:

    WHERE name = 'ABC' 
      AND (category1 = 'X' OR category2 = 'X' OR category3 = 'X')
      AND price < 10
    

提交回复
热议问题