views:

25210

answers:

23

Does anyone know of 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/.Net.

+35  A: 

Have you looked in to Doctrine?

http://www.doctrine-project.org/

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

http://xyster.devweblog.org/

Ian P
+21  A: 

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

Ilya Kochetov
Propel also works well with Symfony, including Symfony2.
analytik
good? by what standards?
stillstanding
@stillstanding Maybe he should have said 2 "known" ones
jblue
+1  A: 

Doctrine is probably your best bet. Prior to Doctrine, this was essentially the only other utility that's open sourced -- http://pear.php.net/package/DB_DataObject/

Good luck.

/sf

Wrong information
Berming
+4  A: 

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.

CMS
+13  A: 

I've been developing Pork.dbObject on my own. (a simple PHP orm / Active Record implementation) The main reason is that i find most orms's too heavy.

The main thought of Pork.dbObejct is to be light-weight and simple to set up. No bunch of xml file, 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

SchizoDuckie
I was looking for a lightweight PHP ORM implementation today, and found Pork.dbObject thanks to this post. It works great! +1
E Dominique
+8  A: 

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.

Alvaro
I tried this. I had to specify the same object properties in 3 places - config, model and database schema. That's a lot of work for implementing an ORM IMO.
mixdev
+5  A: 

I just started with Kohana, and it seems the closest to Rails without invoking all the complexity of multiple config files like with propel.

http://docs.kohanaphp.com/libraries/orm

Zak
A: 

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.

Beau Simensen
+1  A: 

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.

Vance Lucas
+1  A: 

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

knoopx
So how would PHP 5.3 help someone write a better ORM? I don't see any reason.
Ionuț G. Stan
the main reason is the introduction of late static binding ("static" keyword). read about it on http://blog.felho.hu/what-is-new-in-php-53-part-2-late-static-binding.html
knoopx
@knoopx ORM don't really need static variables, they can be well designed using instance variables only.
tomp
A: 

PHP frameworks will show you many php frameworks,you will find what you want.

This is an outdated web site. It even looks like a phishing site with all those non-framework related stuff.
stillstanding
+2  A: 

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);
Olivier Lalonde
A: 

if you are looking for an ORM like hibernate, you should have look at PMO:

http://pmo.developpez.com

It can be easly integrate in an SOA architecture (only a webservice classe to develop)

+16  A: 

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 dont have to write a single... line of code.. http://redbeanphp.com Jesus this orm layer saved me ass!

I just tried it out. It is a hammer!!! I love it!!!
Tom Schaefer
redbean is hands down the best database abstraction layer i've ever worked with. not "one of the best" - the best.
Nir Gavish
Very nice find. I'm very impressed with this ORM to say the least
Chris T
but: http://stackoverflow.com/questions/3212917/redbean-o-rm-store-date-as-varchar255
Sirber
+1  A: 

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 ActiveRecord on rails for PHP. It is still lacking some key features we want such as transactions, composite PK support, a few more adapters (only mysql/sqlite3 work right now). But, we are very close to finishing this stuff up. You can take a look here:

http://www.derivante.com/2009/05/14/php-activerecord-with-php-53/

A: 

Unfortunately both Doctrine and Propel require PDO and don't support legacy database access methods, but my host doesn't enable pdo_mysql :((((((((((((((((. Any PHP ORM that supports legacy access methods?

Please, please, please drop your host. Don't support hosting companies who think that PHP without pdo_mysql is a reasonable platform.
postfuturist
Btw, there's also a pure-PHP implementation of PDO for PHP4, xpdo.org
mario
+2  A: 

Try PHP adodb I cant say it's the best because I havent use the others. But it's fast, it supports memcached, and supports caching. and it's waaaay faster than Zend's DB/Select

adodb lends itself more to the Thin Model/Fat Controller flavor, which is generally not a good thing.
jblue
A: 

PHP ORM Faces For PDO extension PHP Faces Framework

$urun = new Product();
$urun->name=”CPU”
$urun->prince=”124”;
$urun->save();
Kurt
A: 

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 DB and lets you customize them afterward. Works like a charm.

Alex
+2  A: 

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

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

tomp
The only problem I can think of with Doctrine2 is that it's dependent on PHP 5.3 and up.
jblue
@jblue: It's not a problem, it's a feature ;-). Large libraries like Doctrine need namespaces.
tomp
+6  A: 

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, MSSQL/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: 14KB (Axon) + 6KB (SQLdb). Fat-Free is just 55KB.

stillstanding
+2  A: 

I found ORM related classes in the php library Flourish.

VDVLeon
+2  A: 

Has anyone tried the ORM of Flourish library ??

http://flourishlib.com/docs/ObjectRelationalMapping

eaguilar
Yes, I've been working with it for some time. The flourishlib is great, but the ORM still has some work to do. Working with join tables that has additional properties or foreign keys, creating new objects can be a bit tedious. Working with simple models is a breeze. Have a look at Repose ORM or Outlet for an alternative ORM for PHP.
Michael