Porte: Object Relational Mapping (ORM) in PHP

Porte has been designed to save time and to simplify the development of relational database applications written in PHP.

Tired of writing repetitive SQL to interact between your objects and the database, Porte will greatly simplify your life. Porte can retrieve, search and save objects without a single line of SQL. Porte deliver a natural and easy to use framework.

A design goal of Porte was to avoid any external configuration (being XML or others). In its simplest form, a record is a PHP object which class extends "PorteRecord" and which contain its definition in an array called "meta_fields". Getter and setter methods as well as a lot more of goodies will be automatically derived from there.

To some extends, Porte is inspired by Martin Fowler concept of Active Records.

June 26th, 2008: Porte 0.1.9 released

What does it give you?

What it doesn't (yet) give you?

Quick exemple

Create a new group, associate it with a new user and save both

Command: "php samples/home/quick_exemple.php"


class Group extends PorteRecord{
  public $meta_fields = array(
    'name'=>array('size'=>50),
    'users'=>array(
      'has_many'=>true,
    ),
  );
}
      
class User extends PorteRecord{
  public $meta_table = array(
    'name'=>'Users',
    'primary_key'=>'id',
    'encoding'=>'utf8',
  );

  public $meta_fields = array(
    'id'=>array('int'=>11),
    'username'=>array('size'=>50),
    'password'=>array('size'=>50),
    'groups'=>array(
      'has_many'=>true,
    ),
  );
}

PorteConfig::$database = 'porte';
PorteConfig::$connection = new PorteConnection();

$group = new Group();
$group->table->update(array('drop'));
$group->setName('my group');

$user = new User();
$user->table->update(array('drop'))
  ->setUsername('my username')
  ->setPassword('my password')
  ->addGroup($group)
  ->save();

echo 'User id is '.$user->getId()."\r\n";
echo 'Group id is '.$group->getId()."\r\n";

// User id is: 1
// Group id is: 1
    

Open Source Object Relational Mapping in PHP

Download Porte 0.2.0