Explain the concept of an ORM, and what are the tradeoffs of using an ORM versus writing raw SQL?

Last updated 15 June 2026

  • 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.

  • https://www.interviewbit.com/django-interview-questions/
  • https://www.freecodecamp.org/news/a-beginners-guide-to-sql/
  • https://sandeeppant.medium.com/raw-sql-vs-eloquent-when-to-use-which-a635450d5e52
All PHP interview questions