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.
Have you looked in to Doctrine?
http://www.doctrine-project.org/
Also, check out Xyster.. It's based on the Data Mapper pattern.
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.
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
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.
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
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.
I just started with Kohana, and it seems the closest to Rails without invoking all the complexity of multiple config files like with propel.
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.
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.
Until PHP 5.3 release don't expect to have a good ORM. It's a OO limitation of PHP.
PHP frameworks will show you many php frameworks,you will find what you want.
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);
if you are looking for an ORM like hibernate, you should have look at PMO:
It can be easly integrate in an SOA architecture (only a webservice classe to develop)
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!
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/
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?
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
PHP ORM Faces For PDO extension PHP Faces Framework
$urun = new Product();
$urun->name=”CPU”
$urun->prince=”124”;
$urun->save();
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.
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.
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.