Dql select in doctrine vs sql query

老子叫甜甜 提交于 2019-12-13 02:03:00

问题


What is the benefit of use DQL in 'select' statement in doctrine vs native sql?

e.g

     $qb = $em->getRepository('repositoryname')->createQueryBuilder('r);
     $qb->someDqlCondition();
     $qb->getQuery()->getResult();

vs

     $sql = 'string with SELECT sql statement'
     $query = $em->->createQuery($sql)
     $query->getResult();

I discuss about it with my colleague and he say that native sql is better. I think that dql give us ability to change database driver.Is there any other benefit of using dql? What about performance?


回答1:


Doctrine Query Language (DQL) is like an abstraction of your queries. This makes queries independent of the version or type of (SQL) database that your project is built on.

From the documentation:

You need to think about DQL as a query language for your object model, not for your relational schema.

It also means (like @Matteo says in his comment) that you can more easily port your project on another type without having to rewrite all your queries.

Using the doctrine QueryBuilder takes this abstraction to the next level.



来源:https://stackoverflow.com/questions/33932415/dql-select-in-doctrine-vs-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!