<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Geek for Brains</title>
	
	<link>http://geekforbrains.com</link>
	<description>The Thoughts &amp; Works Of A Programmer</description>
	<pubDate>Thu, 06 Nov 2008 20:14:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/GeekForBrains" type="application/rss+xml" /><item>
		<title>Caffeine PHP 2.1 Released</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/407523277/caffeine-php-21-released</link>
		<comments>http://geekforbrains.com/php/caffeine-php-21-released#comments</comments>
		<pubDate>Tue, 30 Sep 2008 18:52:48 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/?p=427</guid>
		<description><![CDATA[
For those who don&#8217;t know, Caffeine PHP is a lite-weight PHP 4 and PHP 5 framework. It&#8217;s an open source project and hosted on Google Code.
Caffeine PHP 2.1 has some exciting new features:

Full documentation in PDF eBook
URI Routing
An anchor utility function for easy URL creation
The ability to use functions or classes in a controller (not [...]]]></description>
			<content:encoded><![CDATA[<p><a style="border: 0" href="http://code.google.com/p/caffeine-php/"><img style="border: 0" src="http://geekforbrains.com/wp-content/uploads/2008/09/caffeine_logo.jpg" alt="Caffeine is a lite-weight PHP 4 and PHP 5 Framework" title="Caffeine PHP 2.1" width="314" height="122" class="size-full wp-image-429" /></a></p>
<p>For those who don&#8217;t know, <a href="http://code.google.com/p/caffeine-php/">Caffeine PHP</a> is a lite-weight PHP 4 and PHP 5 framework. It&#8217;s an open source project and hosted on Google Code.</p>
<p>Caffeine PHP 2.1 has some exciting new features:</p>
<ul>
<li>Full documentation in PDF eBook</li>
<li>URI Routing</li>
<li>An anchor utility function for easy URL creation</li>
<li>The ability to use functions or classes in a controller (not just classes)</li>
<li>Autoloading controllers, models and libraries (not just libraries)</li>
<li>Checks for illegal URL characters</li>
</ul>
<p>Among the above features, Caffeine&#8217;s code has been revised to work smarter and faster then before.</p>
<p><a href="http://code.google.com/p/caffeine-php/">You can download Caffeine PHP 2.1 here.</a></p>
<p>What do you think of the new release?</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/407523277" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/php/caffeine-php-21-released/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/php/caffeine-php-21-released</feedburner:origLink></item>
		<item>
		<title>A Beginners Guide To PHP Classes &amp; Objects - Part 1</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333487/a-beginners-guide-to-php-classes-objects-part-1</link>
		<comments>http://geekforbrains.com/php/a-beginners-guide-to-php-classes-objects-part-1#comments</comments>
		<pubDate>Sat, 27 Sep 2008 05:12:25 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/?p=392</guid>
		<description><![CDATA[PHP Classes. A new programmers night-mare. Don&#8217;t worry, we where all there at one point.
Before you start to glaze over, let me just state that PHP Classes aren&#8217;t complex if you learn them properly. A lot of the time, new programmers will try to learn inheritance, scope etc. right of the bat. I&#8217;d be having [...]]]></description>
			<content:encoded><![CDATA[<p>PHP Classes. A new programmers night-mare. Don&#8217;t worry, we where all there at one point.</p>
<p>Before you start to glaze over, let me just state that PHP Classes aren&#8217;t complex if you learn them properly. A lot of the time, new programmers will try to learn inheritance, scope etc. right of the bat. I&#8217;d be having bad dreams too!</p>
<p>My approach is to teach you in tid-bits. Enough to satisfy those cravings, but won&#8217;t cause indigestion.</p>
<p>For the duration of this article, I&#8217;ll assume you at least know the basics of PHP (variables, functions etc.)</p>
<h2>So What&#8217;s A PHP Class?</h2>
<p>Good question. A PHP Class is nothing more then a bunch of functions, available in one location. Usually these functions do similar or related things.</p>
<p>An example would be a collection of car functions. One tells you how much gas you have, the other tells you how fast you&#8217;re going and another tells you how far you are from your destination.</p>
<p>Thats it! Not so scary is it? (you can put away your teddy-bear now)</p>
<h2>Ok, So What&#8217;s An Object?</h2>
<p>Ah, now this is where a lot of new PHP programmers get confused. Isn&#8217;t an object the same thing as a class? What the heck is the difference?</p>
<p>An Object is a copy of a Class. Think of a Class as a mold. Once you have the mold built, you can make as many copies as you want. I&#8217;ll say it again. An Object is a copy of a Class.</p>
<h2>What Are Object Methods?</h2>
<p>During your journey into PHP classes and objects, you may have come across the term &#8220;class method&#8221; or &#8220;object method&#8221;. What are these?</p>
<p>That&#8217;s easy too! A Method is nothing more then a function inside a class. When a function exists by itself, its called a function. When a function exits inside a class, its called a method.</p>
<h2>What Does A Class Look Like?</h2>
<p>As I said before, classes are collections of functions. Before we look at the structure of a class, lets create the car functions we discussed previously.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Returns how much gas we have</span>
<span style="color: #000000; font-weight: bold;">function</span> check_gas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$gas</span> <span style="color: #339933;">=</span> <span style="">'Half Full'</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$gas</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Returns how fast we're going</span>
<span style="color: #000000; font-weight: bold;">function</span> check_speed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$speed</span> <span style="color: #339933;">=</span> <span style="">'100MPH'</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$speed</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Returns the distance remaining</span>
<span style="color: #000000; font-weight: bold;">function</span> distance_remaining<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$distance</span> <span style="color: #339933;">=</span> <span style="">'20 Miles'</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$distance</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, these functions are pretty straightforward. One obvious limitation is they aren&#8217;t very dynamic.</p>
<p>Now lets take a look at a class. When you create a class, you need to give it a name. Since we&#8217;re using a collection of car functions, we&#8217;ll call our class &#8220;Car&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Define our class as &quot;Car&quot;</span>
<span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how much gas we have</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_gas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$gas</span> <span style="color: #339933;">=</span> <span style="">'Half Full'</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$gas</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how fast we're going</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_speed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$speed</span> <span style="color: #339933;">=</span> <span style="">'100MPH'</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$speed</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns the distance remaining</span>
    <span style="color: #000000; font-weight: bold;">function</span> distance_remaining<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$distance</span> <span style="color: #339933;">=</span> <span style="">'20 Miles'</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$distance</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, all we&#8217;ve done is wrapped our car functions inside a class. A class is defined similar to a function. You start with &#8220;class&#8221; instead of &#8220;function&#8221; and remove the parenthesis &#8220;()&#8221;.</p>
<h2>Creating Copies Of A Class</h2>
<p>Before we continue, I should give you the technical term for creating copies of a class. Its called &#8220;Instantiation&#8221;. Fancy programmer jargon for &#8220;Copy&#8221;. To create an Object of a class, you &#8220;Instantiate&#8221; it. Glad that&#8217;s out the way.</p>
<p>So we&#8217;ve looked at how to create a class (our mold). How do we create copies of the mold? Well, its easier then you might think. Here&#8217;s how it&#8217;s done.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$CarObject</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>As you can see, we&#8217;ve created a variable called $CarObject. We then gave it a value of new Car. The &#8220;new&#8221; keyword is how we create copies of a class. The new keyword is followed by the class we want to create a copy of, followed by parenthesis.</p>
<p>Lets say we had a class called Shoes.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Shoes <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// An empty class...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We could create objects of it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$Shoe1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Shoes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$Shoe2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Shoes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h2>Using PHP Objects</h2>
<p>Great, so now you&#8217;ve created a class called Car, and created an object from it. Now lets take a look at how to use it.</p>
<p>To call an objects methods, you use the variable name of the object, followed by a &#8220;->&#8221; and the method you want to call. Here&#8217;s what it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$MyCar</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Create a new copy of the class</span>
<span style="color: #000088;">$MyCar</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Call the check_gas() method</span></pre></div></div>

<p>Simple huh?</p>
<h2>Object Properties</h2>
<p>As you may have noticed, our class is still very limited. All the values for our gas, speed and destination are hard-coded and can&#8217;t be changed. Lets make our class more dynamic by adding properties.</p>
<p>What are object properties? Object properties are variables that exists within the class. Object properties can be accessed from any of that objects methods or by the object its self.</p>
<p>To access a property from within the class, we use the &#8220;this&#8221; keyword.</p>
<p>Lets update our Car class to use properties.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$gas</span> <span style="color: #339933;">=</span> <span style="">'Half Full'</span>;
    <span style="color: #000088;">$speed</span> <span style="color: #339933;">=</span> <span style="">'100MPH'</span>;
    <span style="color: #000088;">$distance</span> <span style="color: #339933;">=</span> <span style="">'20 Miles'</span>;
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how much gas we have</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_gas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gas</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how fast we're going</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_speed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">speed</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns the distance remaining</span>
    <span style="color: #000000; font-weight: bold;">function</span> distance_remaining<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">distance</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We&#8217;ve moved the variables $gas, $speed and $distance out of their functions and into the class. These are now object properties.</p>
<p>The beauty of properties is when you update them, it effects the entire object. Lets try it now.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$Minivan</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Create a new copy of our car class</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Check the gas (outputs &quot;Half Full&quot;)</span>
<span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gas</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Empty!&quot;</span>; <span style="color: #666666; font-style: italic;">// Update our gas property</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Check the gas again (outputs &quot;Empty!&quot;);</span></pre></div></div>

<p>See how easily we where able to check the gas, update it, and check it again? Now lets try it with multiple Car objects.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$Minivan</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$Truck</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Truck</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span>
&nbsp;
<span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gas</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Empty!&quot;</span>;
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Empty!</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Truck</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span></pre></div></div>

<p>Notice that when we update the Minivan&#8217;s gas, it doesn&#8217;t effect the Truck. This as an important and powerful feature of objects. Changing one object will not effect the other.</p>
<h2>Final Thoughts</h2>
<p>You did it! You&#8217;ve created your own class, created copies of it, gave them properties and accessed their methods! You&#8217;re on your way to object-oriented leetness!</p>
<p>To wrap things up, we&#8217;ll quickly go over the concepts again.</p>
<ul>
<li>A class is a collection of functions</li>
<li>An object is a copy of a class</li>
<li>An method is a function inside a class</li>
<li>An object property is a variable within the class</li>
</ul>
<p>Try playing around with the Car class. Create a bunch of different objects, update the gas, speed and distance, then display them to the browser. Also try creating new methods that perform a new action. An example would be a method that turns the air-conditioning on and off.</p>
<p>You&#8217;ve learned a lot, but your still just scratching the surface. In the coming article, &#8220;A Beginners Guide To PHP Classes &#038; Objects - Part 2&#8243;, I&#8217;ll show you how to really put your objects to work! Make sure to check back soon or subscribe to the RSS feed.</p>
<h2>The Entire Class</h2>
<p>Here&#8217;s the entire class we created throughout this tutorial. Save it in your favorite text editor and play around. If you get stuck, feel free to post your question in the comments!</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Define our class as &quot;Car&quot;</span>
<span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$gas</span> <span style="color: #339933;">=</span> <span style="">'Half Full'</span>;
    <span style="color: #000088;">$speed</span> <span style="color: #339933;">=</span> <span style="">'100MPH'</span>;
    <span style="color: #000088;">$distance</span> <span style="color: #339933;">=</span> <span style="">'20 Miles'</span>;
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how much gas we have</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_gas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gas</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns how fast we're going</span>
    <span style="color: #000000; font-weight: bold;">function</span> check_speed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">speed</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Returns the distance remaining</span>
    <span style="color: #000000; font-weight: bold;">function</span> distance_remaining<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">distance</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$Minivan</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$Truck</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Truck</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span>
&nbsp;
<span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gas</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Empty!&quot;</span>;
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Minivan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Empty!</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$Truck</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check_gas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Half Full</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333487" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/php/a-beginners-guide-to-php-classes-objects-part-1/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/php/a-beginners-guide-to-php-classes-objects-part-1</feedburner:origLink></item>
		<item>
		<title>G4B Photo Gallery Plugin For Wordpress</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333488/g4b-photo-gallery-plugin-for-wordpress</link>
		<comments>http://geekforbrains.com/wordpress/g4b-photo-gallery-plugin-for-wordpress#comments</comments>
		<pubDate>Fri, 26 Sep 2008 21:24:16 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/?p=349</guid>
		<description><![CDATA[G4B Photo Gallery is a free, flexible plugin for Wordpress. It provides a simple and effective way to include a complete gallery anywhere on your site, just by typing in a keyword.
Live Demo
    
    
    
        
   [...]]]></description>
			<content:encoded><![CDATA[<p>G4B Photo Gallery is a free, flexible plugin for Wordpress. It provides a simple and effective way to include a complete gallery anywhere on your site, just by typing in a keyword.</p>
<h2>Live Demo</h2>
<p></p>
<h2>Features</h2>
<ul>
<li>Supports Wordpress 2.2 - 2.6.2</li>
<li>Supports PHP 4 and 5</li>
<li>Supports JPEG, GIF and PNG file types</li>
<li>Easily adjust thumbnail and photo size in settings page</li>
<li>Crop photos or size proportionally</li>
<li>Easily customizable with CSS</li>
</ul>
<h2>Plugin Installation</h2>
<p>The installation procedure is similar to most other Wordpress plugins. Unzip the file and upload its contents to your Wordpress plugin directory. Make sure you keep the directory structure intact. Once uploaded the files should be located at: </p>
<p><code>/wp-content/plugins/G4B_gallery/[php_files_here].</code></p>
<p>In order to upload photos, your upload directory <strong>MUST BE WRITABLE</strong>. When installed, the plugin will automatically create a directory within your plugin directory for storing uploaded photos. The default location is: </p>
<p><code>/wp-content/uploads/g4b_gallery</code></p>
<h2>Usage</h2>
<p>To include your photo gallery on any page or post, type in the keyword:</p>
<p><code>&#123;g4b_gallery&#125;</code></p>
<p>When the content is loaded, the plugin looks for this keyword, and swaps it with the photo gallery dynamically. To remove the gallery from that page or post, simply remove the keyword.</p>
<p>If you would like to embed the plugin using PHP, call the function:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">echo</span> G4B_gallery_view<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The function does not have to be within the Wordpress loop.</p>
<h2>Styling with CSS</h2>
<p>Style your gallery easily by editing the CSS file. The CSS file is located at:</p>
<p><code>/wp-content/plugins/G4B_gallery/G4B_gallery_view.css</code></p>
<h2>Bugs &amp; Suggestions</h2>
<p>If you run into any bugs or have some suggestions, please post them in the comments. That way others can see if the same issue has already been submitted. Thanks!</p>
<h2>Download</h2>
<p><a href="http://wordpress.org/extend/plugins/g4b-photo-gallery/">Download G4B Photo Gallery on Wordpress.org</a></p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333488" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/wordpress/g4b-photo-gallery-plugin-for-wordpress/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/wordpress/g4b-photo-gallery-plugin-for-wordpress</feedburner:origLink></item>
		<item>
		<title>How To Write Your Own MySQL Class In PHP</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333489/how-to-write-your-own-mysql-class-in-php</link>
		<comments>http://geekforbrains.com/php/how-to-write-your-own-mysql-class-in-php#comments</comments>
		<pubDate>Tue, 23 Sep 2008 18:11:47 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/?p=287</guid>
		<description><![CDATA[Writing your own classes can be very satisfying. You expand your programming knowledge, provide yourself with a useful tool and learn about object oriented programming all in one.
Today I&#8217;m going to show you how to write your own MySQL class in PHP 5. We&#8217;ll be using the standard mysql_connect and mysql_query functions to ensure compatibility [...]]]></description>
			<content:encoded><![CDATA[<p>Writing your own classes can be very satisfying. You expand your programming knowledge, provide yourself with a useful tool and learn about object oriented programming all in one.</p>
<p>Today I&#8217;m going to show you how to write your own MySQL class in PHP 5. We&#8217;ll be using the standard mysql_connect and mysql_query functions to ensure compatibility across multiple configurations.</p>
<h2>The Breakdown</h2>
<p>Like any experienced programmer will tell you, you should come up with a battle plan before jumping into code. As tedious as it may seem, it undoubtedly saves you time and frustration in the long run.</p>
<h3>Object variables</h3>
<p>A variety of object variables will be required to hold information while we work with our database.</p>
<ol>
<li><strong>$dbConn</strong>: Database connection link</li>
<li><strong>$dbSql</strong>: Store the loaded SQL statement</li>
<li><strong>$dbQuery</strong>: Store reference to last query</li>
<li><strong>$dbBind</strong>: Stores bound hooks and values</li>
</ol>
<h3>The connect() Method</h3>
<p>The connect method will be used to connect to our MySQL database.</p>
<h3>The prep() Method</h3>
<p>The prep function will be used to load SQL statements into the object and store them in an object variable.</p>
<h3>The bind() Method</h3>
<p>As with most queries, you&#8217;ll need to pass some parameters within your SQL statement. That&#8217;s the role of the bind method. The bind method provides a way to inject values into your SQL statement via the use of hooks. Bound values should automatically be cleaned to avoid SQL injection attacks. We&#8217;ll cover this in more depth later.</p>
<h3>The run() Method</h3>
<p>The run function does as you may expect; it runs the SQL statement we loaded with the prep method. The run function will return the number of rows affected by the statement.</p>
<h3>Helper Methods</h3>
<p>The helper methods will perform common tasks such as get all results, get only one row or count the number of affected rows.</p>
<h2>The Core Class</h2>
<p>Now that we have an outline of what our class looks like, lets get coding. First we&#8217;ll create the class core. In this example, our class name will be MyDB, but you can make it anything you want.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyDB <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbConn</span>;             <span style="color: #666666; font-style: italic;">// Database connection link</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbSql</span>;              <span style="color: #666666; font-style: italic;">// Store the loaded SQL statement</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbQuery</span>;            <span style="color: #666666; font-style: italic;">// Store reference to last query</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbBind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// Stores bound hooks and values</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>The connect() Method</h2>
<p>Ok, so we have our class core. Lets add the connection method to link in our database. Add the following method to your class file.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbHost</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbUser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbPass</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>
        <span style="color: #000088;">$dbHost</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$dbUser</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$dbPass</span>
    <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For simplicity sake, I&#8217;ve used die functions to handle errors. Another approach would be to use PHP 5&#8217;s Exception handler.</p>
<h2>The prep() Method</h2>
<p>As we stated in the class break down, the prep() method will be used to load our SQL statement into an object variable. Add the following method to your class.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> prep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbSql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A simple but important method.</p>
<h2>The bind() Method</h2>
<p>The bind method is where our class starts getting juicy. We&#8217;ll be using this method to load values into our SQL statements via the use of hooks.</p>
<p>The first parameter defines the hook to look for, and the second parameter defines the value to replace the hook with. Values loaded with the bind method should automatically be escaped to avoid SQL injection attacks.</p>
<p>Add the following method to your class file.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bind<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hook</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hook</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, we&#8217;re replacing the hook ($hook) with the value ($value). We&#8217;re also using a method we haven&#8217;t created yet, called escape(). This method will be used to fix any malformed SQL strings. We&#8217;ll be creating the escape() method next.</p>
<h2>The escape() Method</h2>
<p>As stated above, the escape method will be used to fix any malformed SQL strings, and prevent possible SQL injection attacks. The method will be private as its only used by other methods from within the our class.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>The run() Method</h2>
<p>Now that we have all the pre-steps to our query, lets complete it with the run method. This method will run the SQL string loaded with the prep method, and assign the returned query reference to our $dbQuery object variable. The run method will also return the number of rows affected by the query.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbSql</span>;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$hook</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hook</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>;  
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see the query is run while any errors are handled with the die function. Any values set with our bind method are loaded into the SQL statement. A method we haven&#8217;t created is being used as well. The numRows() method is used to determine the number of rows affected by the last query. We&#8217;ll be creating this and other &#8220;helper&#8221; methods next.</p>
<h2>Helper Methods</h2>
<p>The helper methods will be used to perform common tasks on query results. These include fetching all rows, fetching a single row and returning the number of affected rows.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAll<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> MYSQL_ASSOC<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tmpArr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tmpArr</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tmpArr</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAssoc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> numRows<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Usage</h2>
<p>Phew, we&#8217;re done. Lets take this baby for a whirl. First we create our SQL statement and load it with the prep method. Then we&#8217;ll bind some values using the bind method and run it. We&#8217;ll also get the query results using some of our helper methods.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Load our class and instantiate</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="">'MyDB.php'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$MyDB</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Make the connection</span>
<span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="">'localhost'</span><span style="color: #339933;">,</span> <span style="">'demo_database'</span><span style="color: #339933;">,</span> <span style="">'demo_user'</span><span style="color: #339933;">,</span> <span style="">'demo_password'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Load SQL statment into object</span>
<span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prep</span><span style="color: #009900;">&#40;</span><span style="">'SELECT * FROM demo_table WHERE id = :id'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Bind a value to our :id hook</span>
<span style="color: #666666; font-style: italic;">// Produces: SELECT * FROM demo_table WHERE id = '23'</span>
<span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="">':id'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Run the query</span>
<span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Get some results</span>
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAssoc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$MyDB</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h2>The Finished Class</h2>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyDB <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbConn</span>;             <span style="color: #666666; font-style: italic;">// Database connection link</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbSql</span>;              <span style="color: #666666; font-style: italic;">// Store the loaded SQL statement</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbQuery</span>;            <span style="color: #666666; font-style: italic;">// Store reference to last query</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dbBind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// Stores bound hooks and values</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Used to strip slashes and escape strings
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Handles connection to the database.
     * Die functions are used to catch any errors.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbHost</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbUser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbPass</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$dbHost</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$dbUser</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$dbPass</span>
        <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Loads a raw SQL string into the object $dbSql variable
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> prep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbSql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Load bound hooks and values into object variable
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bind<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hook</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$hook</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Runs the SQL string in $dbSql object variable
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbSql</span>;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$hook</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hook</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span>;  
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbBind</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">numRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Used to fetch all rows form the last query in an
     * array. You can define the return type. Default is
     * MYSQL_ASSOC
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAll<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> MYSQL_ASSOC<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tmpArr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tmpArr</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tmpArr</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Returns one row array in associative format
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchAssoc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Returns the number of rows affected by the last query
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> numRows<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbQuery</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-style: italic;">/**
     * Returns the id generated from the last query
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbConn</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Supporting PHP 4</h2>
<p>If you want to be compatible with PHP 4, simply remove the scope definitions (public, private) from the front of class methods and variables.</p>
<h2>Final Thoughts</h2>
<p>Writing your own classes for repetitive PHP tasks not only boosts your productivity, but can be very rewarding. A common saying amongst programmers is &#8220;don&#8217;t re-invent the wheel&#8221;. I beg to differ. If we&#8217;re not constantly creating, updating and exploring, we&#8217;ll never move forward. Inventing new wheels is what makes you a kick-ass programmer.</p>
<p>This is a very basic class, and could easily be tweaked to suit your needs. Some ideas for expansion would be to add more detailed helper methods, or handle errors via the use of Exceptions instead of simple die functions.</p>
<p>If you&#8217;re new to class and objects, check out my post &#8220;<a href="http://geekforbrains.com/php/a-beginners-guide-to-php-classes-objects-part-1">A Beginners Guide To PHP Classes &#038; Objects - Part 1</a>&#8220;.</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333489" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/php/how-to-write-your-own-mysql-class-in-php/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/php/how-to-write-your-own-mysql-class-in-php</feedburner:origLink></item>
		<item>
		<title>Think Organic, Wordpress Theme</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333490/think-organic</link>
		<comments>http://geekforbrains.com/wordpress/think-organic#comments</comments>
		<pubDate>Sun, 17 Aug 2008 05:39:28 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.geekforbrains.com/?p=163</guid>
		<description><![CDATA[Think Organic is my first publicly released Wordpress Theme. Some of its features include Widget support, Gravatar aware, Wordpress 2.6+ compatible and proper display in all major browsers. Any feedback, bug reports or suggestions are appreciated.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekforbrains.com/wp-content/uploads/2008/08/screenshot.png"><img class="alignnone size-full wp-image-166" title="Think Organic Screen Shot" src="http://www.geekforbrains.com/wp-content/uploads/2008/08/screenshot.png" alt="" width="300" height="225" /></a></p>
<p>Think Organic is my first publicly released Wordpress Template. Below is a breakdown of its features.</p>
<ol>
<li>Widget aware</li>
<li><a title="Gravatar" href="http://gravatar.com">Gravtar</a> aware</li>
<li>Wordpress 2.6+ compatible</li>
<li>Correct display in all major browsers</li>
<li>100% height with CSS</li>
<li>Tightly coded</li>
<li>Free!</li>
</ol>
<h2>Installation</h2>
<p>Installation is the same as any other Wordpress Template. Extract the .zip file, upload it to /wp-content/themes and activate in your Wordpress Control Panel.</p>
<h2>Download</h2>
<p>Any suggestion, bug reports or feedback are appreciated.</p>
<p><a title="Download Think Organic v1.0 For Wordpress" href="http://www.geekforbrains.com/wp-content/uploads/2008/08/thinkorganic_v10.zip">Download Think Organic v1.0 for Wordpress</a></p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333490" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/wordpress/think-organic/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/wordpress/think-organic</feedburner:origLink></item>
		<item>
		<title>RipShout Gets An Upgrade</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333492/ripshout-gets-an-upgrade</link>
		<comments>http://geekforbrains.com/software/ripshout-gets-an-upgrade#comments</comments>
		<pubDate>Mon, 11 Aug 2008 16:50:11 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.geekforbrains.com/?p=148</guid>
		<description><![CDATA[
When I first came across RipShout, it was the solution to my Shoutcast ripping needs. You can find my previous review here.
Now, after a bunch of feedback and some hard work from Adam Marciniec; RipShout 1.8 has been released.
Although there weren&#8217;t significant changes to the core, version 1.8 has the old RipShout seasoned with some [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekforbrains.com/wp-content/uploads/2008/08/ripshout_18.jpg"><img class="size-full wp-image-155 alignnone" title="Ripshout 1.8" src="http://www.geekforbrains.com/wp-content/uploads/2008/08/ripshout_18.jpg" alt="Download Ripshout 1.8" width="406" height="273" /></a></p>
<p>When I first came across <a title="RipShout 1.8" href="http://www.rumandcode.com/RipShout/" target="_self">RipShout</a>, it was the solution to my Shoutcast ripping needs. You can find my <a title="Previous RipShout Review" href="http://www.geekforbrains.com/software/rip-your-favorite-shoutcast-streams-with-ripshout" target="_blank">previous review here</a>.</p>
<p>Now, after a bunch of feedback and some hard work from Adam Marciniec; RipShout 1.8 has been released.</p>
<p>Although there weren&#8217;t significant changes to the core, version 1.8 has the old RipShout seasoned with some handy new features. These include upgrades to the internal player, auto-proxy support, the ability to monitor and delete ripped songs and a sexy new interface.</p>
<p>If you haven&#8217;t yet discovered RipShout, your missing out. This app truly is the best way to rip your favorite Shoutcast radio streams, without the crap (or the price!).</p>
<p><a title="Download RipShout 1.8" href="http://www.rumandcode.com/RipShout/" target="_self">You can download RipShout free, here</a>.</p>
<p>Thanks Adam!</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333492" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/software/ripshout-gets-an-upgrade/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/software/ripshout-gets-an-upgrade</feedburner:origLink></item>
		<item>
		<title>Keep Track Of Your Budget With Google Docs</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/315623087/keep-track-of-your-budget-with-google-docs</link>
		<comments>http://geekforbrains.com/web-apps/keep-track-of-your-budget-with-google-docs#comments</comments>
		<pubDate>Thu, 19 Jun 2008 17:58:00 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Web Apps]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/?p=80</guid>
		<description><![CDATA[Google docs is a great tool, and has many potential uses. Budget management is no exception. By creating a simple spreadsheet that calculates incomes, expenses and totals, you can easily get a snap-shot view if money coming in, going out and how much is left over.]]></description>
			<content:encoded><![CDATA[<p>Google docs is a great tool, and has many potential uses. Budget management is no exception. By creating a simple spreadsheet that calculates incomes, expenses and totals, you can easily get a snap-shot view if money coming in, going out and how much is left over. The use of &#8220;Formulas&#8221; such as &#8220;SUM&#8221; allow you to automate the totals.</p>
<p><a href="http://www.geekforbrains.com/wp-content/uploads/2008/06/googledocs_budgetsheet.jpg"><img title="Manage your budget with Google Docs" src="http://geekforbrains.com/wp-content/uploads/2008/06/googledocs_budgetsheet-300x201.jpg" alt="A snapshot of Google Docs budget spreadsheet" width="263" height="176" /></a></p>
<p>I&#8217;ve created a pre-made spreadsheet for you to download and import into your Google Docs to get started. Its a budget sheet for the year. With it you can calculate the totals for each month, and also see a break down of totals for the year.</p>
<p>Because the spreadsheet is in Microsoft Excel (XLS) format, you could use it in Excel or Open Office Calc instead of Google Docs.</p>
<p><a title="Download Google Docs Budget" href="http://www.geekforbrains.com/wp-content/uploads/2008/06/googledocs_budget.zip">Download the spreadsheet here.</a></p>
<h2>Usage</h2>
<p>Using the spreadsheet is easy. Simply enter in the different types of incomes you have, their values as well as the different types of expenses and their values. The totals will automatically be calculated and displayed in the &#8220;Totals&#8221; box.</p>
<p>Remember to update the SUM formula in the total rows if you add more fields to the &#8220;Income&#8221; or &#8220;Expenses&#8221; box. If you dont, your totals may be in-accurate.</p>
<p>Totals for all months will be displayed at the bottom of the spreadsheet. Unless you move any of the &#8220;Totals&#8221; boxes, you should never have to change the formulas in the &#8220;Yearly Totals&#8221; box.</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/315623087" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/web-apps/keep-track-of-your-budget-with-google-docs/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/web-apps/keep-track-of-your-budget-with-google-docs</feedburner:origLink></item>
		<item>
		<title>Easily Grab Screen Colors With ColorPix</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333494/easily-grab-screen-colors-with-colorpix</link>
		<comments>http://geekforbrains.com/software/easily-grab-screen-colors-with-colorpix#comments</comments>
		<pubDate>Tue, 06 May 2008 16:01:36 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/windows/easily-grab-screen-colors-with-colorpix</guid>
		<description><![CDATA[With ColorPix you can easily grap on-screen colors without having to load bloated software such as Photoshop. With the addition of some keyboard shortcuts, this truly is a handy little tool.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekforbrains.com/wp-content/uploads/2008/05/colorpix.gif"><img class="alignleft size-full wp-image-34" title="ColorPix" src="http://www.geekforbrains.com/wp-content/uploads/2008/05/colorpix.gif" alt="" width="115" height="158" /></a>After searching the web for an alternative to pasting screenshots in Photoshop just to get a hex color code; I came across a great, and free tool called ColorPix.</p>
<p>ColorPix is a standalone app that tracks any color your mouse passes over. It also has a viewer that magnifies what your looking at. Once your over the right color, type any key on you keyboard to lock it in ColorPix, then type Ctrl+C to copy the color code.</p>
<p>Simple, light and free. Just the way I like it.</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333494" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/software/easily-grab-screen-colors-with-colorpix/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/software/easily-grab-screen-colors-with-colorpix</feedburner:origLink></item>
		<item>
		<title>NetBeans IDE For PHP</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333495/netbeans-ide-for-php</link>
		<comments>http://geekforbrains.com/software/netbeans-ide-for-php#comments</comments>
		<pubDate>Thu, 01 May 2008 22:55:32 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/php/netbeans-ide-for-php</guid>
		<description><![CDATA[I recently came across a PHP version of the NetBeans IDE. Ok, so its not exactly PHP specific; basically its just a plugin. However, you can download the IDE as a base install specifically for PHP development, excluding any other unecessary languages or plugin bulk.]]></description>
			<content:encoded><![CDATA[<p><a title="NetBeans IDE for PHP" href="http://www.geekforbrains.com/wp-content/uploads/2008/05/netbeans_php_large.jpg"><img src="http://www.geekforbrains.com/wp-content/uploads/2008/05/netbeans_php_small.jpg" alt="NetBeans IDE for PHP" width="406" height="317" /></a></p>
<p>I recently came across a PHP version of the NetBeans IDE. Ok, so its not exactly PHP specific; basically its just a plugin. However, you can download the IDE as a base install specifically for PHP development, excluding any other unecessary languages or plugin bulk.</p>
<p>I&#8217;ve been using the IDE for two days now, and would have to say its a breeze to use. Its packed with features, and yet flexible enough to be a simple PHP editor with syntax highlighting. Its all up to you.</p>
<p>You can find the <a title="NetBeans - Early Access for PHP" href="http://download.netbeans.org/netbeans/6.1/final/">PHP NetBeans IDE here</a>. You want to download the &#8220;Early Access for PHP&#8221; version.</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333495" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/software/netbeans-ide-for-php/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/software/netbeans-ide-for-php</feedburner:origLink></item>
		<item>
		<title>Rip Your Favorite Shoutcast Streams With RipShout</title>
		<link>http://feeds.feedburner.com/~r/GeekForBrains/~3/406333496/rip-your-favorite-shoutcast-streams-with-ripshout</link>
		<comments>http://geekforbrains.com/software/rip-your-favorite-shoutcast-streams-with-ripshout#comments</comments>
		<pubDate>Wed, 23 Apr 2008 18:19:22 +0000</pubDate>
		<dc:creator>Gavin Vickery</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://geekforbrains.com/windows/rip-your-favorite-shoutcast-streams-with-ripshout</guid>
		<description><![CDATA[RipShout is a great freeware tool that rips the streams by song and saves the file by artist name and song title in mp3 format. While ripping a stream you can choose to run quietly in the system tray, play while ripping, or stream through Winamp while ripping.]]></description>
			<content:encoded><![CDATA[<p>I love Shoutcast. Free music, endless streams, minimal ads and a huge selection of genres.</p>
<p>One thing I&#8217;ve always wanted to do is save some of the songs to disk for later listening. Although there are several programs available that already do this, they either don&#8217;t work correctly, require payment or record the entire stream into one mp3; leaving you to split it up.</p>
<p>RipShout is a great freeware tool that rips the streams by song and saves the file by artist name and song title in mp3 format. While ripping a stream you can choose to run quietly in the system tray, play while ripping, or stream through Winamp while ripping.</p>
<p>If you use Shoutcast and want to save some streams, this free tool is for you. You can <a title="RipShout" href="http://www.rumandcode.com/RipShout/">download RipShout for free</a> here.</p>
<img src="http://feeds.feedburner.com/~r/GeekForBrains/~4/406333496" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://geekforbrains.com/software/rip-your-favorite-shoutcast-streams-with-ripshout/feed</wfw:commentRss>
		<feedburner:origLink>http://geekforbrains.com/software/rip-your-favorite-shoutcast-streams-with-ripshout</feedburner:origLink></item>
	</channel>
</rss>
