Good PHP ORM Library?

PhpDatabaseOrm

Php Problem Overview


Is there a good object-relational-mapping library for PHP?

I know of PDO/ADO, but they seem to only provide abstraction of differences between database vendors not an actual mapping between the domain model and the relational model. I'm looking for a PHP library that functions similarly to the way Hibernate does for Java and NHibernate does for .NET.

Php Solutions


Solution 1 - Php

Look into Doctrine.

Doctrine 1.2 implements Active Record. Doctrine 2+ is a DataMapper ORM.

Also, check out Xyster. It's based on the Data Mapper pattern.

Also, take a look at DataMapper vs. Active Record.

Solution 2 - Php

Try RedBean, its requires:

  • No configuration
  • No database (it creates everything on the fly)
  • No models
  • etc.

It even does all the locking and transactions for you and monitors performance in the background. (Heck! it even does garbage collection....) Best of all... you don't have to write a single... line of code... Jesus this, ORM layer, saved me ass!

Solution 3 - Php

There are only two good ones: Doctrine and Propel. We favor Doctrine, and it works well with Symfony. However if you're looking for database support besides the main ones you'll have to write your own code.

Solution 4 - Php

Axon ORM is part of the Fat-Free Framework - it features an on-the-fly mapper. No code generators. No stupid XML/YAML configuration files. It reads the database schema directly from the backend, so in most CRUD operations you don't even have to extend a base model. It works with all major PDO-supported database engines: MySQL, SQLite, SQL Server/Sybase, Oracle, PostgreSQL, etc.

/* SQL */
CREATE TABLE products (
	product_id INTEGER,
	description VARCHAR(128),
	PRIMARY KEY (product_id)
);

/* PHP */
// Create
$product=new Axon('products'); // Automatically reads the above schema
$product->product_id=123;
$product->description='Sofa bed';
$product->save(); // ORM knows it's a new record

// Retrieve
$product->load('product_id=123');
echo $product->description;

// Update
$product->description='A better sofa bed';
$product->save(); // ORM knows it's an existing record

// Delete
$product->erase();

Most of all, the plug-in and accompanying SQL data access layer are just as lightweight as the framework: 14 KB (Axon) + 6 KB (SQLdb). Fat-Free is just 55 KB.

Solution 5 - Php

I've been developing Pork.dbObject on my own. (A simple PHP ORM and Active Record implementation) The main reason is that I find most ORMs too heavy.

The main thought of Pork.dbObejct is to be light-weight and simple to set up. No bunch of XML files, just one function call in the constructor to bind it, and an addRelation or addCustomRelation to define a relation to another dbObject.

Give it a look: Pork.dbObject

Solution 6 - Php

Try Doctrine2. It's probably the most powerful ORM tool for PHP. I'm mentioning it separately from Doctrine 1, because it's a completely different piece of software. It's been rewritten from scratch, is still in beta phase, but it's usable now and developed.

It's a very complex ORM, but well designed. Lot of magic from original Doctrine 1 disappeared. It provides a complete solution, and you can write your own ORM on top of Doctrine2 or use just one of its layers.

Solution 7 - Php

I just started with Kohana, and it seems the closest to Ruby on Rails without invoking all the complexity of multiple configuration files like with Propel.

Solution 8 - Php

I really like Propel, here you can get an overview, the documentation is pretty good, and you can get it through PEAR or SVN.

You only need a working PHP5 install, and Phing to start generating classes.

Solution 9 - Php

Check out Outlet ORM. It is simpler than Propel and Doctrine and it works similar to Hibernate, only with more of a PHP feel to it.

Solution 10 - Php

I found ORM related classes in the PHP library Flourish.

Solution 11 - Php

You should check out Idiorm and Paris.

Solution 12 - Php

Give a shot to dORM, an object relational mapper for PHP 5. It supports all kinds of relationships (1-to-1), (1-to-many), (many-to-many) and data types. It is completely unobtrusive: no code generation or class extending required. In my opinion it is superior to any ORM out there, Doctrine and Propel included. However, it is still in beta and might change significantly in the next couple months. http://www.getdorm.com

It also has a very small learning curve. The three main methods you will use are:

<?php 
$object = $dorm->getClassName('id_here');
$dorm->save($object);
$dorm->delete($object);

Solution 13 - Php

I am currently working on phpDataMapper, which is an ORM designed to have simple syntax like Ruby's Datamapper project. It's still in early development as well, but it works great.

Solution 14 - Php

Solution 15 - Php

I have had great experiences with Idiorm and Paris. Idiorm is a small, simple ORM library. Paris is an equally simple Active Record implementation built on Idiorm. It's for PHP 5.2+ with PDO. It's perfect if you want something simple that you can just drop into an existing application.

Solution 16 - Php

Until PHP 5.3 release don't expect to have a good ORM. It's a OO limitation of PHP.

Solution 17 - Php

My friend Kien and I have improved upon an earlier version of an ORM that he had written prior to PHP 5.3. We have essentially ported over Ruby on Rails' Active Record to PHP. It is still lacking some key features we want such as transactions, composite primary key support, a few more adapters (only MySQL and SQLite 3 work right now). But, we are very close to finishing this stuff up. You can take a look at PHP ActiveRecord with PHP 5.3.

Solution 18 - Php

Try PHP ADOdb.

I can't say it's the best, because I haven't used the others. But it's fast, it supports Memcached and caching.

And it's waaaay faster than Zend Framework's DB/Select.

Solution 19 - Php

Brazilian ORM: http://www.hufersil.com.br/lumine. It works with PHP 5.2+. In my opinion, it is the best choice for Portuguese and Brazilian people, because it has easy-to-understand documentation and a lot of examples for download.

Solution 20 - Php

Have a look at the LEAP ORM for Kohana. It works with a bunch of databases, including DB2, Drizzle, Firebird, MariaDB, SQL Server, MySQL, Oracle, PostgreSQL, and SQLite. With a simple autoload function, it can work with almost any PHP framework. The source code is on GitHub at https://github.com/spadefoot/kohana-orm-leap. You can checkout LEAP's tutorials online.

The ORM library works with non-integer primary keys and composite keys. Connections are managed via a database connection pool and it works with raw SQL queries. The ORM even has a query builder that makes building SQL statements super simple.

Solution 21 - Php

You can check out Repose if you are feeling adventurous. Like Outlet, it is modeled after Hibernate.

It is still very early in its development, but so far the only restrictions on the domain model are that the classes are not marked final and properties are not marked private. Once I get into the land of PHP >= 5.3, I'll try to implement support for private properties as well.

Solution 22 - Php

If you are looking for an ORM that implements the Data Mapper paradigm rather than Active Record specifically, then I would strongly suggest that you take a look at GacelaPHP.

Gacela features:

  • Data mapper
  • Foreign key mapping
  • Association mapping
  • Dependent mapping
  • Concrete table inheritance
  • Query object
  • Metadata mapping
  • Lazy & eager loading
  • Full Memcached support

Other ORM solutions are too bloated or have burdensome limitations when developing anything remotely complicated. Gacela resolves the limitations of the active record approach by implementing the Data Mapper Pattern while keeping bloat to a minimum by using PDO for all interactions with the database and Memcached.

Solution 23 - Php

Agile Toolkit has its own unique implementation of ORM/ActiveRecord and dynamic SQL.

Introduction: http://agiletoolkit.org/intro/1

Syntax (Active Record):

$emp=$this->add('Model_Employee');
$emp['name']='John';
$emp['salary']=500;
$emp->save();

Syntax (Dynamic SQL):

$result = $emp->count()->where('salary','>',400)->getOne();

While Dynamic SQL and Active Record/ORM is usable directly, Agile Toolkit further integrates them with User Interface and jQuery UI. This is similar to JSF but written in pure PHP.

$this->add('CRUD')->setModel('Employee');

This will display AJAXified CRUD with for Employee model.

Solution 24 - Php

MicroMVC has a 13 KB ORM that only relies on a 8 KB database class. It also returns all results as ORM objects themselves and uses late static binding to avoid embedding information about the current object's table and meta data into each object. This results in the cheapest ORM overhead there is.

It works with MySQL, PostgreSQL, and SQLite.

Solution 25 - Php

NotORM

include "NotORM.php";
 $pdo = new PDO("mysql:dbname=software");
 $db = new NotORM($pdo);
 $applications = $db->application()
->select("id, title")
->where("web LIKE ?", "http://%")
->order("title")
->limit(10)
;
foreach ($applications as $id => $application) {
echo "$application[title]\n";
}

Solution 26 - Php

Doctrine is probably your best bet. Prior to Doctrine, DB_DataObject was essentially the only other utility that was open sourced.

Solution 27 - Php

If you are looking for an ORM, like Hibernate, you should have look at PMO.

It can be easily integrated in an SOA architecture (there is only a webservice classe to develop).

Solution 28 - Php

PHP ORM Faces For PDO extension. See PHP Faces Framework.

$urun = new Product();
$urun->name='CPU'
$urun->prince='124';
$urun->save();

Solution 29 - Php

There's a fantastic ORM included in the QCubed framework; it's based on code generation and scaffolding. Unlike the ActiveRecord that's based on reflection and is generally slow, code generation makes skeleton classes for you based on the database and lets you customize them afterward. It works like a charm.

Solution 30 - Php

Look at http://code.google.com/p/lworm/ . It is a really simple, but powerful, lightweight ORM system for PHP. You can also easily extend it, if you want.

Solution 31 - Php

A really good simple ORM is MyActiveRecord. MyActiveRecord documentation. I have been using it a lot and can say it's very simple and well tested.

Solution 32 - Php

Looked at Syrius ORM. It's a new ORM, the project was in a development stage, but in the next mouth it will be released in a 1.0 version.

Solution 33 - Php

Try PdoMap. Wikipedia claims that is inspired by Hibernate. Since I never used Hibernate, I cannot judge :), but I would say from my experience that is good and fast ORM that is easy to implement, with a less steep learning curve that other ORMs.

Solution 34 - Php

Another great open source PHP ORM that we use is PHPSmartDb. It is stable and makes your code more secure and clean. The database functionality within it is hands down the easiest I have ever used with PHP 5.3.

Solution 35 - Php

http://www.shayanderson.com/projects/sado-php-orm.htm" title="PHP ORM and DB layer">Sado is a simple PHP ORM package, easy to use, and offers video tutorials

Solution 36 - Php

I work on miniOrm. Just a mini ORM, for using Object Model & MySQL Abstraction Layer as simply as possible. Hope it may help you : http://jelnivo.fr/miniOrm/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsgibbonsView Question on Stackoverflow
Solution 1 - PhpIan PView Answer on Stackoverflow
Solution 2 - PhpwinterswkView Answer on Stackoverflow
Solution 3 - PhpIlya KochetovView Answer on Stackoverflow
Solution 4 - PhpbcoscaView Answer on Stackoverflow
Solution 5 - PhpSchizoDuckieView Answer on Stackoverflow
Solution 6 - PhpTom PažourekView Answer on Stackoverflow
Solution 7 - PhpZakView Answer on Stackoverflow
Solution 8 - PhpChristian C. SalvadóView Answer on Stackoverflow
Solution 9 - PhpAlvaroView Answer on Stackoverflow
Solution 10 - PhpVDVLeonView Answer on Stackoverflow
Solution 11 - Phpth3mus1cmanView Answer on Stackoverflow
Solution 12 - PhpOlivier LalondeView Answer on Stackoverflow
Solution 13 - PhpVance LucasView Answer on Stackoverflow
Solution 14 - PhpeaguilarView Answer on Stackoverflow
Solution 15 - PhpSander MarechalView Answer on Stackoverflow
Solution 16 - PhpknoopxView Answer on Stackoverflow
Solution 17 - PhpJacques FuentesView Answer on Stackoverflow
Solution 18 - PhpSalam FallView Answer on Stackoverflow
Solution 19 - PhpPaulo AraujoView Answer on Stackoverflow
Solution 20 - PhpMatthewView Answer on Stackoverflow
Solution 21 - PhpBeau SimensenView Answer on Stackoverflow
Solution 22 - PhpNoah GoodrichView Answer on Stackoverflow
Solution 23 - PhpromaninshView Answer on Stackoverflow
Solution 24 - PhpXeoncrossView Answer on Stackoverflow
Solution 25 - PhpCharlie ChaiView Answer on Stackoverflow
Solution 26 - PhpanonView Answer on Stackoverflow
Solution 27 - PhpanonymousView Answer on Stackoverflow
Solution 28 - PhpKurtView Answer on Stackoverflow
Solution 29 - PhpAlex WeinsteinView Answer on Stackoverflow
Solution 30 - PhpFazView Answer on Stackoverflow
Solution 31 - PhpSzymon WygnańskiView Answer on Stackoverflow
Solution 32 - Phpuser538167View Answer on Stackoverflow
Solution 33 - PhpHydrinoView Answer on Stackoverflow
Solution 34 - PhpJoeView Answer on Stackoverflow
Solution 35 - PhpShay AndersonView Answer on Stackoverflow
Solution 36 - PhpCédric MouleyreView Answer on Stackoverflow