Documentation.

Reference Guide

Getting Started

To get started quickly, download the latest release and open demo/ in your browser.

Below are the methods that dORM offers. For the sake of simplicity, we will play with a class named User.

<?php
// See Mapping to learn more about this config file
$dorm = new Dorm("config.xml");

// Loading an object from the database
$user $dorm->getUser($id); // $id could be "1", array("username" => "john"), etc. depending on what your primary key is

// Modifying the object and saving it
$user->email "new-email@domain.com";
$dorm->save($user);

// This will cause an insert since $new_user was not retrieved from database
$new_user = new User();
$dorm->save($new_user);

// Now, if we want to delete $user, all we have to do is
$dorm->delete($user);

// This will return an array with all users
$users $dorm->getUserCollection();

// This will return an array with all users with an ID > 2
$users $dorm->getUserCollection("user_id > :id", array("id" => 2));

Mapping

This is the XML structure used to map your classes to the database.

<dorm>
   <map dsn="mysql://user:pass@hostname/dbname">
      <!-- sample class -->
      <className table="tableName">

         <!-- sample scalar property -->
         <propertyName1 field="fieldName" setter="setterMethod" getter="getterMethod" />

         <!-- sample object property -->
         <propertyName2 fkey="fkeyName" class="objectClassName" setter="setterMethod" getter="getterMethod" />

         <!-- sample object array property -->

         <propertyName3 pivot="pivotTableName" class="objectClassName" key="arrayKeyFieldName" />

      </className>
   </map>
</dorm>
Dsn phptype(dbsyntax)://username:password@protocol+hostspec/database?option=value
Table This is the table that will be used to store your class instances.
Setter OPTIONAL. This is the method to be used by Dorm to set the property. Useful for accessing private properties.
Getter OPTIONAL. This is the method to be used by Dorm to get the property. Useful for accessing private properties.
Field This is the field within the table that will hold your scalar property.
Fkey This is the constraint name (foreign key name) that holds the information to map the object.
Pivot This is the name of the table that will be used as an associative table.
Key OPTIONAL. This is the field you want to use to store the array keys.
Class This is the class name of the object (or object contained in the array for object arrays) that this property holds.

Database Schema

Coming soon! Currently, the schema is reversed engineered from database. Only MySQL with InnoDB engine is currently supported.

Current Limitations

  1. Whenever you update/delete an object, you have to load it first. Solution: We plan to "fix" this as soon as possible !
  2. dORM currently relies on database introspection to generate the database schema. This means that you need to setup foreign keys whenever there is a relationship (1-to-many / many-to-many) and you need to have a primary key on each table. This also means that the introspector might not be compatible with some RDBMS. Solution: We plan to provide an alternative to database introspection by allowing the use of an XML file for generating the database schema. We will also implement introspectors that are adapted to other RDBMS.
  3. Caching system is complicated. Solution: We plan to provide a simple interface to manage dORM's caching system.
  4. Found a bug? Want to request a feature?

For bugs and feature requests, use our bug tracker. Got a question? Ask on our IRC chan (irc.freenode.net #dORM).

Internals Documentation

Data Types

Dorm Type PHP type(s) Database representation
Scalar Boolean, integer, float, string Field
Object Object Foreign key
Object array Array that exclusively contains objects (array key is a scalar) Pivot table
Scalar array To do...

Workflow

Dorm method Action on database by property's Dorm type
Scalar Object Object array Scalar array
GET() If object is cached, return it. Else, LOAD() it and cache it. To do...
SAVE() If object is cached, UPDATE() it. Else, INSERT() it.
DELETE() Delete row. - Delete pivot table associations.
LOAD()* Select all. GET() (lazy loading) GET() on each object from array (lazy loading)
INSERT()* Insert all. SAVE() all objects. Insert foreign keys in local table. SAVE() on each object from array. Insert associations in pivot table.
UPDATE()* Update all. SAVE() all objects. Update foreign keys in local table. SAVE() on each object from array. Delete all current associations. Insert new associations in pivot table.

* LOAD(), INSERT() and UPDATE() should never be used by end-users.