Dql在教义vs SQL查询中选择 [英] Dql select in doctrine vs sql query

查看:63
本文介绍了Dql在教义vs SQL查询中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学说与本机sql的'select'语句中使用DQL有什么好处?

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

例如

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

vs

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

我与同事讨论了这个问题,他说原生sql更好。
我认为dql使我们能够更改数据库驱动程序。使用dql还有其他好处吗?性能如何?

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?

推荐答案

Doctrine Query Language (DQL)就像对查询的抽象。这使查询独立于项目所基于的(SQL)数据库的版本或类型。

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.

从文档中:


您需要考虑DQL作为对象模型而不是关系模式的查询语言。

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

这也意味着(如@Matteo在他的评论中所说),您可以更轻松地将项目移植到另一种类型上,而不必重写所有查询。

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.

使用 该学说 QueryBuilder 将此抽象带到下一个层次。

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

这篇关于Dql在教义vs SQL查询中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆