difference between orm and pdo

后端 未结 2 1670
一生所求
一生所求 2021-01-31 04:54

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 als

相关标签:
2条回答
  • 2021-01-31 05:04

    No, they're different things.

    PDO is an abstraction layer for connections to SQL databases, so you can use the same code to work with MySQL, PostgreSQL etc.

    ORM is the concept of mapping database entities to objects. Doctrine is an example of a PHP ORM framework that supports various different ways of connecting to databases, one of which is PDO.

    0 讨论(0)
  • 2021-01-31 05:16

    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.

    0 讨论(0)
提交回复
热议问题