orm和pdo之间的区别 [英] difference between orm and pdo

查看:100
本文介绍了orm和pdo之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于ORM和PDO之间的区别,我有些困惑吗?
PDO是一种ORM吗?

根据我的理解,ORM基本上是一种数据映射,PDO还提供了数据库数据的抽象.

解决方案

PDO和ORM是两个完全不同的东西.

PDO是数据库访问抽象层的特定实现,它使您可以连接,运行SQL并使用跨不同数据库后端(例如MySQL,PostgreSQL,MS SQL等)一致的API从数据库检索结果. )

另一方面,ORM更专业:这是一个用于将关系表映射到应用程序域对象及其之间关系的框架.这些通常是建立在PDO之类的DAL之上的.

要查看区别,请考虑必须检索对象或记录.使用PDO,您需要编写SQL以在正确的表中选择正确的行,并具有提取该行并将字段映射到PHP对象的变量的逻辑.您作为用户必须照顾好这一切. 另一方面,使用ORM,您只需说:通过此ID找到对象X,ORM便会尽其所能并为您提供该对象,而无需您自己编写SQL.

I have a little confusion regarding difference between ORM and PDO?
Is PDO a kind of ORM?

ORM as per my understanding is basically a kind of data mapping and PDO also provides an abstraction for the database data.

解决方案

PDO and ORM are two entirely different things.

PDO is a specific implementation of a Database Access Abstraction Layer, it enables you to connect, run SQL and retrieve results from the database with an API that is consistent across different database backends (e.g. MySQL, PostgreSQL, MS SQL, etc.)

An ORM on the other hand is something more specialised: It's a framework for mapping relational tables to application domain objects and relationships between them. These are often built on top of DALs like PDO.

To see the difference, consider having to retrieve an object or record. With PDO, you'd need to write SQL for selecting the right row in the right table, and have logic for extracting that row, and mapping the fields to a PHP object's variables. You as the user have to take care of all this. On the other hand, with an ORM, you'd simply say: find me the Object X by this ID, and the ORM would do its magic and give you that object, without you having to write the SQL yourself.

这篇关于orm和pdo之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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