My apps…

Space Harvest Begin

All-Seeing Interactive is a tiny web design and software company based in London, UK.

Saturday 3 January 2009

Introducing FuzzyRecord: A Rails-like Active record implementation for PHP 5.3

FuzzyRecord is an Object-Relational-Mapping (ORM) system for PHP applications, based on the Active record design pattern, most famously used in Ruby On Rails.

It makes use of the new Late Static Binding features in PHP 5.3, which basically makes static methods a lot more useful. As a result, it has a clean API not dissimilar from Rails:


$user = User::find_by_email("ben@allseeing-i.com");
$user = User::find_by_first_name_and_last_name("Ben","Copsey");
$articles = Article::find_all_by_date_greater_than("2008-07-07");
$users = User::find(
  "first_name" => "Ben", 
  "start_from" => 10,
  "order_by" => "last_name",
  "sort" => "ascending", 
  "where" => "status = 'validated'"
);
$photos = $user->photos;
$photos = Photo::find_all();
$user->photos = $photos;
if (!$user->save()) {
  print_r($user->validation_errors);
}

Along with a nice API for querying your data, it supports:

  • validating properties (eg: max / min length, is an email address etc)
  • relationships with cascade update / delete
  • integer, natural and composite primary keys
  • explicit and automatic transactions
  • Data caching to reduce database load, including Memcached support

It currently supports MySQL databases, but the database access layer is based on PDO, and I expect to add Postgres support soon.

Documentation is available here:http://allseeing-i.com/FuzzyRecord.

You can grab the latest source with git:

$ git clone git://github.com/pokeb/fuzzy-record.git

Or just get a tarball here:

http://github.com/pokeb/fuzzy-record/tarball/master

Posted by Ben @ 3:37 PM