Porte: Object Relational Mapping (ORM) in PHP
Porte has been design to save time and simplify the development of relational database applications written in PHP. It provides a clean and natural API with a maximum of flexibility.
Tired of writting repetitive sql to persist your object in the database, Porte will greatly simplify your life. Porte can retrieve, search and save object without a single line of Sql. We worked hard to deliver a framework natural and easy to use without being over intrusive. All functionnalities are create at runtime and no PHP code is generated. You can but are not force to create record classes which extends the PorteRecord class to overwrite or enhance the native implementation.
Porte has been tested with PHP 5.2.x and PHP 5.3.x and MySQL 5.0.45 (MySQL Community Server). It should work with any version of PHP superior to 5.2.x and of MySQL version superior to 5.0.x. If any doubts, simply run the test suite.
Key functionnalities
- Plugable architecture
- Multiple model (or schema) mechanisms
- Associations (one-to-one, one-to-many, many-to-many, parent-child)
- Record lazy-loading
- Index & unique keys support
- Sql injection safe
- Events notification
- Multi-databases support
- Table automatic migration
- Full test coverage (+ many samples)
Quick exemple
The following code create a new group, associate it with a new user and save the two records into the database.
class Group extends PorteRecord{
public $config = array(
'properties' => array(
'name'=>array('size'=>50),
'users'=>array( 'has_many' )
)
);
}
class User extends PorteRecord{
public $config = array(
'name'=>'Users',
'primary_key'=>'id_user',
'encoding'=>'utf8',
'properties' => array(
'id_user'=>array('int'=>11),
'username'=>array('size'=>50),
'password'=>array('size'=>50),
'groups'=>array( 'has_many' )
)
);
}
Porte::$database = 'porte';
Porte::$porte = new Porte();
$group = new Group();
$group->table->update(array('drop'));
$group->setName('my group');
$user = new User();
$user->table->update(array('drop'));
$user->setUsername('my username')
->setPassword('my password')
->addGroup($group)
->save();
echo 'User id is '.$user->getIdUser()."\r\n";
echo 'Group id is '.$group->getId()."\r\n";
// User id is: 1
// Group id is: 1