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 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.
MySQLi is a replacement for the mysql functions, with object-oriented and procedural versions. It has support for prepared statements. PDO (PHP Data Objects) is a general database abstraction layer with support for MySQL among many other databases.
PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier.
PDO (PHP Data Objects) is an abstraction layer for your database queries and is an awesome alternative to MySQLi, as it supports 12 different database drivers. This is an immense benefit for people and companies that need it. However, keep in mind that MySQL is by far the most popular database.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With