21

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?

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Don't know of any. Good question! – Till Oct 22 '08 at 01:15
  • The fact that this question is the highest google page for the term "Entity Attribute Value framework" and the page is only 8 hours old would suggest you're out of luck. That said, if you were to use something like the Zend Framwork, you could easily extend the Zend_DB_Table abstract class. – Andrew Taylor Oct 22 '08 at 08:36
  • @Andrew I believe your Google search may be influenced by your location or search history. For the same search, I do not see stackoverflow in the top 100 results. A Google search no longer gives a single results page with objective data. It seems to be unavoidably subjective in some way. – Liam Oct 28 '08 at 14:47
  • I don't have an answer, but I just read about this recently in php|architect. http://www.phparch.com/c/magazine/issue/76 Might help you find more info... –  Oct 29 '08 at 14:01

3 Answers3

4

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
  • 7,367
  • 4
  • 22
  • 15
1

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
  • 24,875
  • 14
  • 66
  • 96
1

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
  • 11,039
  • 3
  • 32
  • 38
  • that sounds horrible for performance, albeit flexible - maybe even too much. – Keyframe Mar 20 '09 at 05:43
  • 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 Mar 28 '09 at 01:50
  • 1
    "EAV-style" and "normalized" are antonyms. – Bill Karwin Nov 06 '09 at 02:45
  • @Bill Karwin: I can certainly see the drawbacks of EAV (as illustrated by Magento), but what would you propose as a replacement when you need a flexible data model, such as for storing custom product attributes or designing custom forms? – Lèse majesté Dec 07 '10 at 13:18
  • 2
    @Lèse majesté: See my answer to http://stackoverflow.com/questions/695752/ or my book, *SQL Antipatterns: Avoiding the Pitfalls of Database Programming* http://www.pragprog.com/titles/bksqla/ – Bill Karwin Dec 07 '10 at 17:25
  • @Bill, what eZ Publish does (or did when I wrote this) is use a heavily normalized SQL structure as the storage backend for the EAV-style data model. The EAV data isn't itself normalized. Sorry that was unclear. – joelhardi Jan 01 '11 at 23:36