doctrine: QueryBuilder vs createQuery?

后端 未结 5 839
青春惊慌失措
青春惊慌失措 2020-12-23 14:20

In Doctrine you can create DQL in 2 ways:

EntityManager::createQuery:

$query = $em->createQuery(\'SELECT u FROM MyProject\\Model\         


        
5条回答
  •  旧巷少年郎
    2020-12-23 15:01

    1. DQL is easier to read as it is very similar to SQL. If you don't need to change the query depending on a set of parameters this is probably the best choice.

    2. Query Builder is an api to construct queries, so it's easier if you need to build a query dynamically like iterating over a set of parameters or filters. You don't need to do any string operations to build your query like join, split or whatever.

提交回复
热议问题