Unlike PHP_UML, Dorm does not belong to any framework. It is therefore possible to use it directly in a PHP application, simply by including the file Dorm.php.
The only requirement is the presence, on your system, of either MDB2 or ADOdb, depending on the abstraction layer you want to use along with the ORM.


The software is available on Sourceforge.

Basic example

And here is the dorm-mapping.xml configuration file:

<?xml version="1.0"?>
  <class name="User" table="User">
    <property name="id" index="primary" column="id"/>
    <property name="first_name" column="first_name"/>
    <property name="last_name" column="last_name"/>
Note how you map the class User to the table User, and the class property first_name to the column first_name.

Here is the source code:

require_once 'PEAR/Exception.php';
require_once 'MDB2.php';
require_once 'MDB2/iterator.php';
require_once 'dorm.php';

$mdb2 = MDB2::connect('mysql://...');

// Dorm initialization
  new Dorm_Model('dorm-mapping.xml'),

// Definition of the PHP class
Class User {
  public $id;
  public $first_name;
  public $last_name;

// Insert
$u = new User;
$u->first_name = 'Robinson';
$u->last_name = 'Crusoe';
echo "The inserted id was ".$u->id;

// Retrieval
$set = Dorm::select("User", "WHERE last_name LIKE 'Cru%'");
foreach($set as $user)
  echo '<br/>'.$user->first_name.' '.$user->last_name;