<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP &amp; MySQL Tip #3 &#8211; EAV Modeling w/ PHP &amp; MySQL</title>
	<atom:link href="http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/</link>
	<description>Ranging from PHP &#38; MySQL to Random Crap from the internet, I got it all here.</description>
	<lastBuildDate>Thu, 26 Aug 2010 05:56:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Web Resources.eu</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-58</link>
		<dc:creator>Web Resources.eu</dc:creator>
		<pubDate>Thu, 26 Aug 2010 05:56:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-58</guid>
		<description>Very nice article.

The EAV model you described is realy very simple and helpfull even for not expirienced users !</description>
		<content:encoded><![CDATA[<p>Very nice article.</p>
<p>The EAV model you described is realy very simple and helpfull even for not expirienced users !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dschreck</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-46</link>
		<dc:creator>dschreck</dc:creator>
		<pubDate>Thu, 19 Nov 2009 06:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-46</guid>
		<description>Spirit: 

Technically EAV is the idea that only one entity can have any number of attributes, and one attribute can have any number of values. 

So what you&#039;re describing sounds somewhat on track with this design pattern.</description>
		<content:encoded><![CDATA[<p>Spirit: </p>
<p>Technically EAV is the idea that only one entity can have any number of attributes, and one attribute can have any number of values. </p>
<p>So what you&#8217;re describing sounds somewhat on track with this design pattern.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spirit</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-45</link>
		<dc:creator>spirit</dc:creator>
		<pubDate>Sun, 08 Nov 2009 10:27:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-45</guid>
		<description>Hey, thanks for the article. I first attempt for me to understand EAV. 

Then with this structure would it be possible to construct a category tree built from one attribute. I mean all my item have 3 main attribute then a user would be allowed to have his category tree built from attribute1 or attribute2...

Any thoughts ?</description>
		<content:encoded><![CDATA[<p>Hey, thanks for the article. I first attempt for me to understand EAV. </p>
<p>Then with this structure would it be possible to construct a category tree built from one attribute. I mean all my item have 3 main attribute then a user would be allowed to have his category tree built from attribute1 or attribute2&#8230;</p>
<p>Any thoughts ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dschreck</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-7</link>
		<dc:creator>dschreck</dc:creator>
		<pubDate>Fri, 17 Oct 2008 16:26:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-7</guid>
		<description>It would depend on your hardware set up.

Having PHP build the pivot data per request could be extremely time consuming and CPU intensive. So I would recommend having Memcache sever set up, and then use another machine as a cron runner, which handles such things by periodically updating the memcache arrays. 

You could go extremely in depth and have it update when changes occur, and that&#039;d just have to depend on how often your data set changes vs how often the cron runner runs.

Again, this can be accomplished just the same by doing &lt;code&gt;CREATE [or an INSERT INTO TABLE] `&lt;pivot_table_data&gt;` SELECT ...&lt;/code&gt; queries - which you can also use MySQL Query caching if you could find a balance of: how often the data is updated, how often it needs to be re-pivoted, how &#039;fresh&#039; does the content need to be.

I prefer the first example I gave you, creating a pivot data table, which is just update in batch process or cron process.</description>
		<content:encoded><![CDATA[<p>It would depend on your hardware set up.</p>
<p>Having PHP build the pivot data per request could be extremely time consuming and CPU intensive. So I would recommend having Memcache sever set up, and then use another machine as a cron runner, which handles such things by periodically updating the memcache arrays. </p>
<p>You could go extremely in depth and have it update when changes occur, and that&#8217;d just have to depend on how often your data set changes vs how often the cron runner runs.</p>
<p>Again, this can be accomplished just the same by doing <code>CREATE [or an INSERT INTO TABLE] `
<pivot_table_data>` SELECT ...</pivot_table_data></code> queries &#8211; which you can also use MySQL Query caching if you could find a balance of: how often the data is updated, how often it needs to be re-pivoted, how &#8216;fresh&#8217; does the content need to be.</p>
<p>I prefer the first example I gave you, creating a pivot data table, which is just update in batch process or cron process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: edesign</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-6</link>
		<dc:creator>edesign</dc:creator>
		<pubDate>Fri, 17 Oct 2008 06:32:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-6</guid>
		<description>Do you think creating the pivoted table via PHP and then storing it as a cached temporary table would make sense?   It would have to be rebuilt via PHP if an edit to any of the existing elements happened?</description>
		<content:encoded><![CDATA[<p>Do you think creating the pivoted table via PHP and then storing it as a cached temporary table would make sense?   It would have to be rebuilt via PHP if an edit to any of the existing elements happened?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dschreck</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-5</link>
		<dc:creator>dschreck</dc:creator>
		<pubDate>Fri, 17 Oct 2008 03:41:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-5</guid>
		<description>You could always try something like:

&lt;pre&gt;
CREATE TABLE pivot_data (
SELECT
items.item_name,
ia.attribute_name,
av.attribute_value
FROM
attribute_values AS av
JOIN item_attributes AS ia
ON (ia.id = av.attribute_id)
JOIN items AS items
ON (items.id = ia.item_id)
);
&lt;/pre&gt;

Which will give you a bulk extraction, with this data you can preform &quot;warehouse&quot; queries. This again, just an example of how you can implement an EAV Like system. 


You can also load up this kind of bulk extraction as an array stored in memcache, which you update periodically, or create a view (MySQL 5)

I wouldn&#039;t really agree with creating a view, but it is a known way to optimize your performance while pivoting. Though you should take care and optimize your view&#039;s, and use them sparingly. 

If I had to go either way, I would set up a cron or trigger system to update/create my pivot data sets in a batch process. 
Or even if the application allows it, have an update system which can be triggered only when needed.

Hope that helps.</description>
		<content:encoded><![CDATA[<p>You could always try something like:</p>
<pre>
CREATE TABLE pivot_data (
SELECT
items.item_name,
ia.attribute_name,
av.attribute_value
FROM
attribute_values AS av
JOIN item_attributes AS ia
ON (ia.id = av.attribute_id)
JOIN items AS items
ON (items.id = ia.item_id)
);
</pre>
<p>Which will give you a bulk extraction, with this data you can preform &#8220;warehouse&#8221; queries. This again, just an example of how you can implement an EAV Like system. </p>
<p>You can also load up this kind of bulk extraction as an array stored in memcache, which you update periodically, or create a view (MySQL 5)</p>
<p>I wouldn&#8217;t really agree with creating a view, but it is a known way to optimize your performance while pivoting. Though you should take care and optimize your view&#8217;s, and use them sparingly. </p>
<p>If I had to go either way, I would set up a cron or trigger system to update/create my pivot data sets in a batch process.<br />
Or even if the application allows it, have an update system which can be triggered only when needed.</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: edesign</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-4</link>
		<dc:creator>edesign</dc:creator>
		<pubDate>Fri, 17 Oct 2008 02:17:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-4</guid>
		<description>Silly me, it was late last night I wasn&#039;t looping through the mysql_fetch_assoc.   Do you have an example of pivoting the data, I was thinking there was a way to do it with just MySQL alone?  Any thoughts?</description>
		<content:encoded><![CDATA[<p>Silly me, it was late last night I wasn&#8217;t looping through the mysql_fetch_assoc.   Do you have an example of pivoting the data, I was thinking there was a way to do it with just MySQL alone?  Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dschreck</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-3</link>
		<dc:creator>dschreck</dc:creator>
		<pubDate>Thu, 16 Oct 2008 17:01:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-3</guid>
		<description>edesign:
Pivoting is generally used when combining any type of row-modeled data, you&#039;ll usually combine that into a column like set up, for using &#039;off the shelf&#039; reporting software.

I&#039;m not exactly sure what you mean when you say it only brings back one attribute?

Using the direct copy and paste of the tables above, i quickly typed out these test data inserts:

&lt;code&gt;
insert into items values (1, &#039;item 1&#039;), (2, &#039;item 2&#039;), (3, &#039;item 3&#039;);
insert into item_attributes values (1, 1, &#039;att1 for item 1&#039;), (2, 1, &#039;att2 for item 1&#039;);
insert into item_attributes values (3, 2, &#039;att1 for item 2&#039;), (4, 2, &#039;att2 for item 2&#039;);
insert into item_attributes values (5, 3, &#039;att1 for item 3&#039;), (6, 3, &#039;att2 for item 3&#039;);
insert into attribute_values values (1, &#039;value for att 1&#039;),  (2, &#039;value for att 2&#039;), (3, &#039;value for att 3&#039;), (4, &#039;value for att 4&#039;), (5, &#039;value for att 5&#039;), (6, &#039;value for att 6&#039;);
&lt;/code&gt;

then, running the query i give as an example, i get this output:

&lt;pre&gt;
item_name 	attribute_name 	attribute_value
item 1 	att1 for item 1 	value for att 1
item 1 	att2 for item 1 	value for att 2
item 2 	att1 for item 2 	value for att 3
item 2 	att2 for item 2 	value for att 4
item 3 	att1 for item 3 	value for att 5
item 3 	att2 for item 3 	value for att 6
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>edesign:<br />
Pivoting is generally used when combining any type of row-modeled data, you&#8217;ll usually combine that into a column like set up, for using &#8216;off the shelf&#8217; reporting software.</p>
<p>I&#8217;m not exactly sure what you mean when you say it only brings back one attribute?</p>
<p>Using the direct copy and paste of the tables above, i quickly typed out these test data inserts:</p>
<p><code><br />
insert into items values (1, 'item 1'), (2, 'item 2'), (3, 'item 3');<br />
insert into item_attributes values (1, 1, 'att1 for item 1'), (2, 1, 'att2 for item 1');<br />
insert into item_attributes values (3, 2, 'att1 for item 2'), (4, 2, 'att2 for item 2');<br />
insert into item_attributes values (5, 3, 'att1 for item 3'), (6, 3, 'att2 for item 3');<br />
insert into attribute_values values (1, 'value for att 1'),  (2, 'value for att 2'), (3, 'value for att 3'), (4, 'value for att 4'), (5, 'value for att 5'), (6, 'value for att 6');<br />
</code></p>
<p>then, running the query i give as an example, i get this output:</p>
<pre>
item_name 	attribute_name 	attribute_value
item 1 	att1 for item 1 	value for att 1
item 1 	att2 for item 1 	value for att 2
item 2 	att1 for item 2 	value for att 3
item 2 	att2 for item 2 	value for att 4
item 3 	att1 for item 3 	value for att 5
item 3 	att2 for item 3 	value for att 6
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: edesign</title>
		<link>http://www.iwilldomybest.com/2008/08/php-mysql-tip-3/comment-page-1/#comment-2</link>
		<dc:creator>edesign</dc:creator>
		<pubDate>Thu, 16 Oct 2008 07:13:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.iwilldomybest.com/2008/08/25/php-mysql-tip-3/#comment-2</guid>
		<description>Your SELECT statement only returns one attribute?  Can you elaborate on the SELECT statement to bring back several attributes at once?  I think in the EAV model this is called Pivoting, I was wondering if there was a way to do from MySQL directly?</description>
		<content:encoded><![CDATA[<p>Your SELECT statement only returns one attribute?  Can you elaborate on the SELECT statement to bring back several attributes at once?  I think in the EAV model this is called Pivoting, I was wondering if there was a way to do from MySQL directly?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
