A minimalist ORM for PHP.

0.8.0 2015-05-07 10:14 UTC


Phormium is a minimalist ORM for PHP.

Tested on Informix, MySQL, PosgreSQL and SQLite. Might work on other databases with a PDO driver or may require some work.

Warning: This is a work in progress. Test before using! Report any bugs here.

Latest Stable Version Total Downloads Build Status Coverage Status


  • CRUD operations made simple
  • batch update and delete
  • filtering
  • ordering
  • limiting
  • transactions
  • custom queries
  • events


The documentation is hosted by


After initial setup, Phormium is very easy to use. Here's a quick overview of it's features:

// Create a new person record
$person = new Person();
$person->name = "Frank Zappa";
$person->birthday = "1940-12-21";

// Get record by primary key
Person::get(10);   // Throws exception if the model doesn't exist
Person::find(10);  // Returns null if the model doesn't exist

// Check record exists by primary key

// Also works for composite primary keys
Post::get('2013-01-01', 100);
Post::find('2013-01-01', 100);
Post::exists('2013-01-01', 100);

// Primary keys can also be given as arrays
Post::get(['2013-01-01', 100]);
Post::find(['2013-01-01', 100]);
Post::exists(['2013-01-01', 100]);

// Fetch, update, save
$person = Person::get(10);
$person->salary += 5000; // give the man a raise!

// Fetch, delete

// Intuitive filtering, ordering and limiting
$persons = Person::objects()
    ->filter('salary', '>', 10000)
    ->filter('birthday', 'between', ['2000-01-01', '2001-01-01'])
    ->orderBy('name', 'desc')

// Count records
$count = Person::objects()
    ->filter('salary', '>', 10000)

// Check if any records matching criteria exist
$count = Person::objects()
    ->filter('salary', '>', 10000)

// Distinct values
$count = Person::objects()
    ->distinct('name', 'email');

// Complex composite filters
$persons = Person::objects()->filter(
            array('id', '>=', 10),
            array('id', '<=', 20)
            array('id', '>=', 50),
            array('id', '<=', 60)
        array('id', '>=', 100),

// Fetch a single record (otherwise throws an exeption)
$person = Person::objects()
    ->filter('email', '=', '')

// Batch update
    ->filter('salary', '>', 10000)
    ->update(['salary' => 5000]);

// Batch delete
    ->filter('salary', '>', 10000)

// Aggregates
Person::objects()->filter('name', 'like', 'Ivan%')->avg('salary');
Person::objects()->filter('name', 'like', 'Marko%')->min('birthday');

// Custom filters with argument binding
    ->filter("my_func(salary) > ?", [100])

See documentation for full reference, also check out the example directory for more examples.


"Why another ORM?!?", I hear you cry.

There are two reasons:

  • I work a lot on Informix on my day job and no other ORM I found supports it.
  • Writing an ORM is a great experience. You should try it.

Phormium is greatly inspired by other ORMs, in particular:

Let me know what you think!

Ivan Habunek @ihabunek


If you like it, buy me a beer (in Croatia, that's around €2 or $3).

Flattr this


Licensed under the MIT license. See