<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dawnerd &#187; database</title>
	<atom:link href="http://dawnerd.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://dawnerd.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 13 Aug 2010 18:20:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Optimizing Dynamic Content With Memcached</title>
		<link>http://dawnerd.com/post/16_optimizing-dynamic-content-with-memcached/</link>
		<comments>http://dawnerd.com/post/16_optimizing-dynamic-content-with-memcached/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 06:41:11 +0000</pubDate>
		<dc:creator>Troy Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://dawnerd.com/?p=16</guid>
		<description><![CDATA[I have posted before on how to use Memcached to reduce database load, but I failed to give a sound example. Hopefully this will rectify that. Please read this post to catch up if you haven&#8217;t already. otherwise I will &#8230; <a href="http://dawnerd.com/post/16_optimizing-dynamic-content-with-memcached/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have posted before on how to use <a href="http://www.danga.com/memcached/">Memcached</a> to reduce database load, but I failed to give a sound example. Hopefully this will rectify that. Please <a href="http://dawnerd.com/php/2008/05/07/using-memcached-to-reduce-database-load/">read this post</a> to catch up if you haven&#8217;t already. otherwise I will assume you have experience with Memcached.<span id="more-16"></span></p>
<p>In this scenario, you have a custom built blog application that has a section with the latest posts. Instead of constantly pulling this text from the database or saving the output to text files, which can be slow, saving the test into memory may be the best solution.</p>
<p>Take the following code:</p>
<pre>
<code>
$sql = "SELECT * FROM posts ORDER BY date LIMIT 5";
$query = mysql_query($sql);
if(mysql_num_rows($query)
{
     while($row=mysql_fetch_array($query))
     {
          echo "
<h2>".$row['title']."</h2>

";
     }
}
</code>
</pre>
<p>Lets make that faster.</p>
<pre>
<code>
$memcache = new Memcache;
$memcache->connect('memcache_host', 11211);
if(!$memcache->get('recent_posts'))
{
     $sql = "SELECT * FROM posts ORDER BY date LIMIT 5";
     $query = mysql_query($sql);
     $post_array = array();
     if(mysql_num_rows($query)
     {
          while($row=mysql_fetch_array($query))
          {
               $post_array[] = $row;
          }
     }
    //recent expires in one hour
    $memcache->set('recent_posts',$post_Array, 0, 3600);
}

$recent_posts = $memcache->get('recent_posts');
for($i=0;$i<count($recent_posts);$i++)
{
     echo "
<h2>".$recent_posts[$i]['title']."</h2>

";
}
</code>
</pre>
<p>You won&#8217;t notice a large increase if your site is small, but if you have a busy site and you have a bunch of spare ram, you might as well put it to use. In the future I will show you some more examples of real-world usage of <a href="http://www.danga.com/memcached/">Memcached</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dawnerd.com/post/16_optimizing-dynamic-content-with-memcached/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Solution To Minify Data From Different Locations</title>
		<link>http://dawnerd.com/post/13_simple-solution-to-minify-data-from-different-locations/</link>
		<comments>http://dawnerd.com/post/13_simple-solution-to-minify-data-from-different-locations/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 18:32:38 +0000</pubDate>
		<dc:creator>Troy Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[data collection]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://dawnerd.com/?p=13</guid>
		<description><![CDATA[Lets say you use a forum software and a blogging software as the backend of your website. Lets also say that you want to create profiles for your members, but neither the forum or the blog software have the support &#8230; <a href="http://dawnerd.com/post/13_simple-solution-to-minify-data-from-different-locations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lets say you use a forum software and a blogging software as the backend of your website. Lets also say that you want to create profiles for your members, but neither the forum or the blog software have the support you in, and in addition you need info from both the blog and the forum. <span id="more-13"></span></p>
<p>Instead of having two different arrays of data to show a user&#8217;s information, you can combine both arrays together with <code>array_merge()</code>. This is one of my favorite php functions as it really saves you hassles.</p>
<p>This:</p>
<pre>
<code markup="none">
echo $forum_array['name']." - ".$blog_array['blogpost_count'];
</code>
</pre>
<p>Can become:</p>
<pre>
<code markup="none">
echo $user['name']." - ".$user['blogpost_count'];
</code>
</pre>
<p>Not only is it already shorter, but there is less to have to remember. All the data is right there. And to do that all you would need to do is:</p>
<pre>
<code markup="none">
$user = array_merge($forum_array,$blog_array);
</code>
</pre>
<p>Of course <code>array_merge()</code> can be used for other things as well, such as combining POST and GET data into a single array (which hopefully you would run an XSS check on it all).</p>
]]></content:encoded>
			<wfw:commentRss>http://dawnerd.com/post/13_simple-solution-to-minify-data-from-different-locations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
