<?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>Andrew Bellamy &#187; PHP</title>
	<atom:link href="http://www.andrew-bellamy.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrew-bellamy.co.uk</link>
	<description></description>
	<lastBuildDate>Tue, 22 Jun 2010 16:45:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Value Object Class</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/value-object-class/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/value-object-class/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:00:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=178</guid>
		<description><![CDATA[Value class that hold values. Can be used with any class that returns an array of values Usage]]></description>
			<content:encoded><![CDATA[<p>Value class that hold values.  Can be used with any class that returns an array of values</p>
<h4>Usage</h4</p>
<pre class="brush: php;">
$temp = new ValueObject(
			array(
				&quot;value1&quot; =&gt; &quot;value&quot;,
				&quot;value2&quot; =&gt; 2,
				&quot;value3&quot; =&gt; 123.123,
				&quot;value4&quot; =&gt; &quot;value&quot;
			)
		);
echo $temp-&gt;value1;
</pre>
<h4>Code</h4>
<pre class="brush: php;">
class ValueObject {

	private $properties = array();

	public function __construct($values = array()) {
		foreach($values as $key =&gt; $value)
			$this-&gt;properties[$key] = $value;
	}

	public function __set($key = &quot;&quot;, $value = &quot;&quot;) {
		$this-&gt;properties[$key] = $value;
	}

	public function __get($key = &quot;&quot;) {
		if(array_key_exists($key, $this-&gt;properties))
			return $this-&gt;properties[$key];
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/value-object-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Class</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/mysql-class/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/mysql-class/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:00:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=170</guid>
		<description><![CDATA[Class that interacts with MySQL, performing INSERT, UPDATE, DELETE and SELECT, at the moment Usage $single = &#34;&#34;; $multi =&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/06/mysql-class/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<p>Class that interacts with MySQL, performing INSERT, UPDATE, DELETE and SELECT, at the moment</p>
<h4>Usage</h4>
<pre class="brush: php;">
$single = &quot;&quot;;
$multi = array();

$mySQL = new MySQL(
			array(
				&quot;Server&quot; =&gt; &quot;localhost&quot;,
				&quot;Username&quot; =&gt; &quot;Username&quot;,
				&quot;Password&quot; =&gt; &quot;Password&quot;,
				&quot;Database&quot; =&gt; &quot;Database&quot;
			)
		);

/* Without Errors or use above
$mySQL = new MySQL(
			array(
				&quot;Server&quot; =&gt; &quot;localhost&quot;,
				&quot;Username&quot; =&gt; &quot;Username&quot;,
				&quot;Password&quot; =&gt; &quot;Password&quot;,
				&quot;Database&quot; =&gt; &quot;Database&quot;
			),
			false
		);
*/

/* With Errors
$mySQL = new MySQL(
			array(
				&quot;Server&quot; =&gt; &quot;localhost&quot;,
				&quot;Username&quot; =&gt; &quot;Username&quot;,
				&quot;Password&quot; =&gt; &quot;Password&quot;,
				&quot;Database&quot; =&gt; &quot;Database&quot;
			),
			true
		);
*/

$mySQL-&gt;open();
$mySQL-&gt;selectWhere(&quot;TableName&quot;, null, array(&quot;id&quot; =&gt; 1));
while($row = $mySQL-&gt;results()) {
	$single = new ValueObject($row);
	$single-&gt;toString();
}
$mySQL-&gt;close();

$mySQL-&gt;open();
$mySQL-&gt;select(&quot;TableName&quot;);
while($row = $mySQL-&gt;results())
	$multi[] = new ValueObject($row);

$mySQL-&gt;close();

for($a = 0; $a &lt; sizeof($multi); $a++)
	$multi[$a]-&gt;toString();

$mySQL-&gt;open();
$mySQL-&gt;insert(&quot;TableName&quot;, array(&quot;value1&quot; =&gt; 789, &quot;value2&quot; =&gt; &quot;TEST6&quot;, &quot;value3&quot; =&gt; &quot;2010-06-19&quot;, &quot;value4&quot; =&gt; 6));
$mySQL-&gt;close();

$mySQL-&gt;open();
$mySQL-&gt;update(&quot;TableName&quot;, array(&quot;value1&quot; =&gt; 789, &quot;value2&quot; =&gt; &quot;TEST3&quot;, &quot;value3&quot; =&gt; &quot;2010-06-18&quot;, &quot;value4&quot; =&gt; 3), array(&quot;id&quot; =&gt; 3));
$mySQL-&gt;close();

$mySQL-&gt;open();
$mySQL-&gt;delete(&quot;TableName&quot;, array(&quot;id&quot; =&gt; 3));
$mySQL-&gt;close()
</pre>
<h4>Code</h4>
<pre class="brush: php;">
class MySQL {

	private $properties = array(
					&quot;ConnectionProperties&quot; =&gt; array(
										&quot;Server&quot; =&gt; null,
										&quot;Username&quot; =&gt; null,
										&quot;Password&quot; =&gt; null,
										&quot;Database&quot; =&gt; null
									),
					&quot;Connection&quot; =&gt; null,
					&quot;Result&quot; =&gt; null,
					&quot;InsertID&quot; =&gt; null,
					&quot;Error&quot; =&gt; array(
									&quot;SetError&quot; =&gt; false
								)
					);

	public function __construct($values = array(), $error = false) {
		foreach($values as $key =&gt; $value)
			$this-&gt;properties[&quot;ConnectionProperties&quot;][$key] = $value;

		$this-&gt;properties[&quot;Error&quot;][&quot;SetError&quot;] = $error;
	}

	public function __set($key = &quot;&quot;, $value = &quot;&quot;) {
		$this-&gt;properties[$key] = $value;
	}

	public function __get($key = &quot;&quot;) {
		if(array_key_exists($key, $this-&gt;properties))
			return $this-&gt;properties[$key];
	}

	public function open() {
		$this-&gt;properties[&quot;Connection&quot;] = mysql_connect($this-&gt;properties[&quot;ConnectionProperties&quot;][&quot;Server&quot;], $this-&gt;properties[&quot;ConnectionProperties&quot;][&quot;Username&quot;], $this-&gt;properties[&quot;ConnectionProperties&quot;][&quot;Password&quot;]);
		if(!$this-&gt;properties[&quot;Connection&quot;]) {
			$this-&gt;error();
		} else
			mysql_select_db($this-&gt;properties[&quot;ConnectionProperties&quot;][&quot;Database&quot;], $this-&gt;properties[&quot;Connection&quot;]);
	}

	public function close() {
		if(mysql_insert_id($this-&gt;properties[&quot;Connection&quot;]) != 0 || mysql_insert_id($this-&gt;properties[&quot;Connection&quot;]) != null || mysql_insert_id($this-&gt;properties[&quot;Connection&quot;]) != false)
			if($this-&gt;properties[&quot;Result&quot;]) {
				mysql_free_result($this-&gt;properties[&quot;Result&quot;]);
				$this-&gt;properties[&quot;Result&quot;] = null;
			}

		mysql_close($this-&gt;properties[&quot;Connection&quot;]);
	}

	public function select($table = null, $columns = null, $condition = array()) {
		$conditionSize = sizeof($condition);
		$columnSize = sizeof($columns);
		$a = 0;
		$column = &quot;&quot;;
		$where = &quot;&quot;;

		if($columns == null) {
			$column .= &quot;*&quot;;
		} else {
			for($a = 0; $a &lt; $columnSize; $a++) {
				if($a &lt; ($columnSize - 1))
					$column .= $columns[$a].&quot;, &quot;;
				else
					$column .= $columns[$a];
			}
		}

		if($condition == null)
			$where .= &quot; &quot;;
		else {
			$where .= &quot; WHERE &quot;;
			foreach ($condition as $key =&gt; $value) {
				if(is_numeric($value)) {
					if($a == ($conditionSize - 1))
						$where .= $key.' = '.$value;
					else
						$where .= $key.' = '.$value.' AND ';
				} else {
					if($a == ($conditionSize - 1))
						$where .= $key.&quot; = '&quot;.$value.&quot;'&quot;;
					else
						$where .= $key.&quot; = '&quot;.$value.&quot;' AND &quot;;
				}
				$a++;
			}
		}

		if(!$this-&gt;properties[&quot;Result&quot;] = mysql_query(&quot;SELECT &quot;.$column.&quot; FROM &quot;.$table.$where, $this-&gt;properties[&quot;Connection&quot;])) {
			$this-&gt;error();
		}
	}

	public function insert($table = &quot;&quot;, $values = array()) {
		$size = sizeof($values);
		$columns = &quot;&quot;;
		$temp = &quot;&quot;;

		$a = 0;
		foreach ($values as $key =&gt; $value) {
			if($a == ($size - 1))
				$columns .= $key;
			else
				$columns .= $key.', ';

			$a++;
		}

		$a = 0;
		foreach ($values as $key =&gt; $value) {
			if(is_numeric($value)) {
				if($a == ($size - 1))
					$temp .= $value;
				else
					$temp .= $value.', ';
			} else {
				if($a == ($size - 1))
					$temp .= &quot;'&quot;.$value.&quot;'&quot;;
				else
					$temp .= &quot;'&quot;.$value.&quot;', &quot;;
			}
			$a++;
		}

		if(!$this-&gt;properties[&quot;Result&quot;] = mysql_query(&quot;INSERT INTO &quot;.$table.&quot; (&quot;.$columns.&quot;) VALUES (&quot;.$temp.&quot;)&quot;, $this-&gt;properties[&quot;Connection&quot;])) {
			$this-&gt;error();
		} else
			$this-&gt;properties[&quot;InsertID&quot;] = mysql_insert_id($this-&gt;properties[&quot;Connection&quot;]);
	}

	public function update($table = &quot;&quot;, $values = array(), $condition = array()) {
		$size = sizeof($values);
		$conditionSize = sizeof($condition);
		$temp = &quot;&quot;;

		$a = 0;
		foreach ($values as $key =&gt; $value) {
			if(is_numeric($value)) {
				if($a == ($size - 1))
					$temp .= $key.&quot; = &quot;.$value;
				else
					$temp .= $key.&quot; = &quot;.$value.', ';
			} else {
				if($a == ($size - 1))
					$temp .= $key.&quot; = &quot;.&quot;'&quot;.$value.&quot;'&quot;;
				else
					$temp .= $key.&quot; = &quot;.&quot;'&quot;.$value.&quot;', &quot;;
			}
			$a++;
		}

		$where = &quot; WHERE &quot;;
		$a = 0;
		foreach ($condition as $key =&gt; $value) {
			if(is_numeric($value)) {
				if($a == ($conditionSize - 1))
					$where .= $key.' = '.$value;
				else
					$where .= $key.' = '.$value.' AND ';
			} else {
				if($a == ($conditionSize - 1))
					$where .= $key.&quot; = '&quot;.$value.&quot;'&quot;;
				else
					$where .= $key.&quot; = '&quot;.$value.&quot;' AND &quot;;
			}
			$a++;
		}
		if(!$this-&gt;properties[&quot;Result&quot;] = mysql_query(&quot;UPDATE &quot;.$table.&quot; SET &quot;.$temp.$where, $this-&gt;properties[&quot;Connection&quot;])) {
			$this-&gt;error();
		}
	}

	public function delete($table = &quot;&quot;, $condition = array()) {
		$conditionSize = sizeof($condition);
		$where = &quot; WHERE &quot;;
		$a = 0;

		foreach ($condition as $key =&gt; $value) {
			if(is_numeric($value)) {
				if($a == ($conditionSize - 1))
					$where .= $key.' = '.$value;
				else
					$where .= $key.' = '.$value.' AND ';
			} else {
				if($a == ($conditionSize - 1))
					$where .= $key.&quot; = '&quot;.$value.&quot;'&quot;;
				else
					$where .= $key.&quot; = '&quot;.$value.&quot;' AND &quot;;
			}
			$a++;
		}

		if(!$this-&gt;properties[&quot;Result&quot;] = mysql_query(&quot;DELETE FROM &quot;.$table.$where, $this-&gt;properties[&quot;Connection&quot;])) {
			$this-&gt;error();
		}
	}

	public function results() {
		return mysql_fetch_object($this-&gt;properties[&quot;Result&quot;]);
	}

	private function error() {
		if($this-&gt;properties[&quot;Error&quot;][&quot;SetError&quot;])
			echo &quot;MySQL Error: (&quot;. mysql_errno().&quot;) &quot;.mysqlerror().&quot;&lt;br /&gt;&quot;;
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/mysql-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LDAP Authentication</title>
		<link>http://www.andrew-bellamy.co.uk/2009/08/ldap-authentication/</link>
		<comments>http://www.andrew-bellamy.co.uk/2009/08/ldap-authentication/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 19:02:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=32</guid>
		<description><![CDATA[WordPress Plugin The code for my LDAP Authentication is available below LDAP Authentication(zip) Install the plugin, fill in the options&#160;[<a href="http://www.andrew-bellamy.co.uk/2009/08/ldap-authentication/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>WordPress Plugin</h4>
<p>The code for my LDAP Authentication is available below</p>
<p><a href="http://www.andrew-bellamy.co.uk/wp-content/uploads/2009/08/ldap-authentication.zip">LDAP Authentication</a><span id="file-type">(zip)</span></p>
<p>Install the plugin, fill in the options and thats it</p>
<p>Please e-mail me if there are any problems/improvements</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2009/08/ldap-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Andy&#8217;s Crumbs</title>
		<link>http://www.andrew-bellamy.co.uk/2009/08/andys-crumbs/</link>
		<comments>http://www.andrew-bellamy.co.uk/2009/08/andys-crumbs/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 19:01:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=29</guid>
		<description><![CDATA[WordPress Plugin The code for my Andy&#8217;s Crumbs is available below Andy&#8217;s Crumbs(zip) Install the plugin, follow the instructions, done&#160;[<a href="http://www.andrew-bellamy.co.uk/2009/08/andys-crumbs/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h3>WordPress Plugin</h3>
<p>The code for my Andy&#8217;s Crumbs is available below</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2009/08/andys-crumbs.zip'>Andy&#8217;s Crumbs</a><span id="file-type">(zip)</span></p>
<p>Install the plugin, follow the <a href="http://wordpress.org/extend/plugins/andys-crumbs/installation/">instructions</a>, done</p>
<p>Please e-mail me if there are any problems/improvements</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2009/08/andys-crumbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
