PHP: tips/resources/patterns for learning to implement a basic ORM

Posted by BoltClock on Stack Overflow See other posts from Stack Overflow or by BoltClock
Published on 2010-05-22T09:08:45Z Indexed on 2010/05/22 9:10 UTC
Read the original article Hit count: 296

Filed under:
|
|
|
|

I've seen various MVC frameworks as well as standalone ORM frameworks for PHP, as well as other ORM questions here; however, most of the questions ask for existing frameworks to get started with, which is not what I'm looking for. (I have also read this SO question but I'm not sure what to make of it, and the answers are vague.)

Instead, I figured I'd learn best by getting my hands dirty and actually writing my own ORM, even a simple one. Except I don't really know how to get started, especially since the code I see in other ORMs is so complicated.

With my PHP 5.2.x (this is important) MVC framework I have a basic custom database abstraction layer, that has:

  • Very simple methods like connect($host, $user, $pass, $base), query($sql, $binds), etc
  • Subclasses for each DBMS that it supports
  • A class (and respective subclasses) to represent SQL result sets

But does not have:

  • Active Record functionality, which I assume is an ORM thing (correct me if I'm wrong)

I've read up a little about ORM, and from my understanding they provide a means to further abstract data models from the database itself by representing data as nothing more than PHP-based classes/objects; again, correct me if I am wrong or have missed out in any way.

Still, I'd like some simple tips from anyone else who's dabbled more or less with ORM frameworks. Is there anything else I need to take note of, simple example code for me to refer to, or resources I can read? Thanks a lot in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about database