Explain the concept of an ORM, and what are the tradeoffs of using an ORM versus writing raw SQL?
Last updated
An ORM (Object-Relational Mapper) maps tables to classes and rows to objects, so you work with PHP objects (e.g.
$user->save()) instead of hand-written SQL.Benefits: faster development, readable code, database portability, and SQL injection protection via parameter binding.
Costs: performance overhead, the N+1 query problem (lazy loading in loops), and awkwardness with complex queries. Use the ORM for CRUD and raw SQL for performance-critical or analytical queries.