数据库抽象层和数据库之间有什么区别?数据访问层? [英] What is the difference between Database Abstraction Layer & Data Access Layer?

查看:233
本文介绍了数据库抽象层和数据库之间有什么区别?数据访问层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上陷入了三层结构。我上网冲浪,发现了两个术语数据库抽象层和 数据访问层。

I am actually stuck in 3-tier structure. I surfed the internet and found two terminologies "Database Abstraction Layer" & "Data Access Layer".

两者之间有什么区别?

推荐答案

我的理解是,数据访问层实际上并没有抽象数据库,而是使数据库操作和查询构建更容易。

My understanding is that a data access layer does not actually abstract the database, but rather makes database operations and query building easier.

例如,数据访问层通常,它们的API与SQL语法非常相似,但仍需要了解数据库的结构才能编写:

For example, data access layers usually have APIs very similar to SQL syntax that still require knowledge of the database's structure in order to write:

$Users->select('name,email,datejoined')->where('rank > 0')->limit(10);

数据抽象层通常是完整的ORM(对象关系映射器),从理论上讲,它们不需要理解任何基础数据库结构或任何SQL知识。语法可能是这样的:

Data abstraction layers are usually full blown ORM's (Object-Relational Mappers) that theoretically prevent the need to understand any underlying database structure or have any knowledge of SQL. The syntax might be something like this:

Factory::find('Users', 10)->filter('rank > 0');

所有对象可能都充满了所有字段,并可能与任何父对象或子对象一起加入

And all the objects might be fully populated with all the fields, possibly joined with any parent or child objects if you set it that way.

但是,这种抽象是有代价的。我个人认为ORM之类的学说或推动力是不必要且效率低下的。在大多数情况下,简单的数据访问层就可以很好地完成工作,对于需要特别注意的任何事情,都可以使用手动SQL来完成,而不必为了某些语法而破坏应用程序的性能。这个领域是一个非常激烈的辩论,所以我不再赘述。

However, this abstraction comes with a price. I personally find ORM's like doctrine or propel to be unnecessary and inefficient. In most cases a simple data access layer will do fine, with manual SQL for anything that requires special attention, instead of having to destroy your application's performance for some syntactic sugar. This area is a pretty heated debate so I won't go into it anymore.

如果您的意思是数据基本抽象层,那么它将与PDO相似,因此您的代码可用于更多的数据库供应商。我相信PDO可以与MySQL,PostgreSQL和mysqli一起使用。

If you meant database abstraction layer, then it would be something along the lines of PDO, so that your code can be used for a larger number of database vendors. PDO works with MySQL, PostgreSQL, and mysqli among others, I believe.

这篇关于数据库抽象层和数据库之间有什么区别?数据访问层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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