#native_company# #native_desc#
#native_cta#

A Practical Approach to Object-Relational Mapping in PHP Page 2

By PHP Builder Staff
on March 8, 2004

Background
Suppose your company breeds hippos for the army. Some are used as beasts of burden. Others are equipped with
weapons, like pie throwers, and spit projectors. Your company doesn’t install the weapons, just the sockets
the weapons plug into. Armed hippos can have more than one mount point.
First, we’ll create the hippos table, with the fields id and name.
Field Type Notes
id integer Primary key
Auto increment
name text  
Now some PHP. For simplicity, methods not directly related to the topic we’re discussing have been omitted.

<?php

class Hippo 

{

    var 
$id null;

    var 
$name null;

    
//Load record from DB

    
function load($id

    {

        ...

    }

    
//Save record to DB

    
function save() 

    {

        ...

    }

}

?>



Hippo is a “business classes,” that is, a class describing something meaningful to
nontechnical people in the business. Some classes do not correspond to business entities. For
example, classes for database objects, like Table, Record, and Field, might not mean anything
to the average sales representative. However, he or she will understand what a Hippo is, and
will know that they have id numbers and names.

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|