views:

2866

answers:

5

Is there a Entity Attribute Value framework out there for PHP/MySQL? I'm starting to write my own, but I feel like its been done already. Any suggestions?

+2  A: 

I think Magento makes use of an EAV style architecture, might be worth having a look in there. Magento is an ecommerce platform based on the Zend Framework.

Dave Marshall
A: 

I've always written my own. But then it was always on top of an object abstraction layer that I had already written, so I could leverage a lot of existing code.

Mind you, I've never been impressed with the quality of code in PEAR, so that would probably influence why I've always preferred to write my own abstraction layers.

staticsan
+1  A: 

There does not currently appear to be an EAV Framework in PHP / MySQL; however, I did find these two links that might be of some assistance:

http://www.planetmysql.org/entry.php?id=14025

http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/

Noah Goodrich
A: 

I don't know of any.

With that said, the eZ Publish ECMS (which is FOSS) uses an EAV-style, heavily normalized data model. Both definitions of types of structured content ("content classes") and actual instances of content (articles, user accounts, comments, products, anything really) are defined and stored in single database tables.

This way, arbitrary combinations of datatypes can be dynamically combined through the web interface to make a new content type (a "simplearticle" might consist of a "Textline" for headline, "Datetime" for publish date and "XML field" for body text). In EAV, "simplearticle" is the entity, "headline" an attribute name and "Textline" its value, while the length and validation rules comprising the "Textline" datatype are metadata in the EAV context.

As expected with any EAV architecture, this flexibility comes at the cost of reduced performance, since any lookup requires multiple self-joins, one for each column in the pivoted result set.

Unfortunately, this stack hasn't make it into eZ's related eZ Components library (which has database and data access object/ORM components, but of the standard relational variety), so using it would mean either dealing with the whole eZ Publish enchilada or ripping the required class libraries out yourself.

joelhardi
that sounds horrible for performance, albeit flexible - maybe even too much.
Keyframe
It *is* horrible for performance. eZ Publish does several levels of caching to make this workable (the "content classes" and content itself are only reread/joined from the db when they've changed) but it's still slower than either a relational structure or native object store like BigTable.
joelhardi
"EAV-style" and "normalized" are antonyms.
Bill Karwin
+1  A: 

Yes there is: http://sourceforge.net/projects/eavframework It's still a work in progress, but it's a start!

Willo