<?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</title>
	<atom:link href="http://www.andrew-bellamy.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrew-bellamy.co.uk</link>
	<description></description>
	<lastBuildDate>Sun, 22 Aug 2010 09:00:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ROAOnline</title>
		<link>http://www.andrew-bellamy.co.uk/2010/08/roaonline/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/08/roaonline/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 09:00:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[mooTools]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=259</guid>
		<description><![CDATA[An web application that will access MySQL, PostgreSQL or MSSQL databases to store secondary (Year 7 &#8211; 10) students&#8217; Record&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/08/roaonline/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<p>An web application that will access MySQL, PostgreSQL or MSSQL databases to store secondary (Year 7 &#8211; 10) students&#8217; Record of Achievement&#8217;s</p>
<p>Availble from (hopefully) December 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/08/roaonline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>add a new user to active directory</title>
		<link>http://www.andrew-bellamy.co.uk/2010/08/add-a-new-user-to-active-directory/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/08/add-a-new-user-to-active-directory/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 18:13:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=228</guid>
		<description><![CDATA[App.config Change the following code to what you require &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34; ?&#62; &#60;configuration&#62; &#60;configSections&#62; &#60;sectionGroup name=&#34;LDAP&#34;&#62; &#60;section name=&#34;Connection&#34; type=&#34;System.Configuration.NameValueSectionHandler,&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/08/add-a-new-user-to-active-directory/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>App.config</h4>
<p>Change the following code to what you require</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
	&lt;configSections&gt;
		&lt;sectionGroup name=&quot;LDAP&quot;&gt;
			&lt;section name=&quot;Connection&quot; type=&quot;System.Configuration.NameValueSectionHandler, System,Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /&gt;
			&lt;section name=&quot;Directory&quot; type=&quot;System.Configuration.NameValueSectionHandler, System,Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /&gt;
			&lt;section name=&quot;Misc&quot; type=&quot;System.Configuration.NameValueSectionHandler, System,Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /&gt;
		&lt;/sectionGroup&gt;
	&lt;/configSections&gt;

	&lt;LDAP&gt;
		&lt;Connection&gt;
			&lt;add key=&quot;Server&quot; value=&quot;ServerName&quot; /&gt;
			&lt;add key=&quot;OU&quot; value=&quot;OU=Users,DC=Test,DC=Local&quot; /&gt;
			&lt;add key=&quot;Username&quot; value=&quot;ServerUsername&quot; /&gt;
			&lt;add key=&quot;Password&quot; value=&quot;ServerPassword&quot; /&gt;
			&lt;add key=&quot;DomainRoot&quot; value=&quot;Test.Local&quot; /&gt;
		&lt;/Connection&gt;

		&lt;Directory&gt;
			&lt;add key=&quot;HomeDirectoryPath&quot; value=&quot;\\Test\Users\&quot; /&gt;
			&lt;add key=&quot;HomeDrive&quot; value=&quot;U&quot; /&gt;
		&lt;/Directory&gt;

		&lt;Misc&gt;
			&lt;add key=&quot;Email&quot; value=&quot;@test.com&quot; /&gt;
		&lt;/Misc&gt;
	&lt;/LDAP&gt;
&lt;/configuration&gt;
</pre>
<h4>C# Code</h4>
<p>The code below does not require changing as it uses the code above</p>
<pre class="brush: csharp;">
//  App.config
private NameValueCollection LdapConnectionConfig = (NameValueCollection)ConfigurationManager.GetSection(&quot;Ldap/Connection&quot;);
private NameValueCollection LdapDirectoryConfig = (NameValueCollection)ConfigurationManager.GetSection(&quot;Ldap/Directory&quot;);
private NameValueCollection LdapMiscConfig = (NameValueCollection)ConfigurationManager.GetSection(&quot;Ldap/Misc&quot;);

public CreateUser(string username, string forename, string surname) {
	try
	{
		//  Create Connection to LDAP
		using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, LdapConnectionConfig[&quot;Server&quot;], LdapConnectionConfig[&quot;OU&quot;]))
		{
			//  Create User Object to Check Already Exist
			using (UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, username))
			{
				if (userPrincipal == null)
				{
					//  Create User Object - Setting Username, Password and Enabling Account
					using (UserPrincipal user = new UserPrincipal(principalContext, username, &quot;xxxx1111!&quot;, true))
					{
						//  Assign Properties to User
						user.GivenName = forename;
						user.Surname = surname;
						user.DisplayName = forename + &quot; &quot; + surname;  //  Forename Surname
						user.Name = forename + &quot; &quot; + surname;  //  Forename Surname
						user.EmailAddress = username + LdapMiscConfig[&quot;Email&quot;];  //  jdoe@test.com
						user.HomeDirectory = LdapDirectoryConfig[&quot;HomeDirectoryPath&quot;] + username;  //  C:\Files\USERNAME, \\Server\Files\Username
						user.HomeDrive = LdapDirectoryConfig[&quot;HomeDrive&quot;];  //  U:\
						user.UserPrincipalName = username + LdapConnectionConfig[&quot;DomainRoot&quot;];  //  jdoe@test.local

						//  User Must Change Password as First Logon
						user.ExpirePasswordNow();

						//  Save User
						user.Save();
					}
				}
			}
		}

		return true;
	}
	catch (PrincipalException e)
	{
		return false;
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/08/add-a-new-user-to-active-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mooTools Request.JSON</title>
		<link>http://www.andrew-bellamy.co.uk/2010/08/mootools-request-json/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/08/mootools-request-json/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 20:00:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mooTools]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=253</guid>
		<description><![CDATA[I had a look at mooTools documentation for Request.JSON and managed to confuse myself It took me four attempts to&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/08/mootools-request-json/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<p>I had a look at mooTools documentation for <a href="http://mootools.net/docs/core/Request/Request.JSON">Request.JSON</a> and managed to confuse myself</p>
<p>It took me four attempts to get the following code right.  The code calls a webservice created in ASP.net C#.</p>
<h4>code</h4</p>
<pre class="brush: jscript;">
new Request.JSON({
	headers: { &#8216;Accept&#8217;: &#8216;application/json&#8217;, &#8216;X-Request&#8217;: &#8216;JSON&#8217;, &#8216;Content-Type&#8217;: &#8216;application/json&#8217; },
	urlEncoded: false,
	url: &quot;WEBSERVICE URL&quot;,  //  webservice/method
	method: &#8216;post&#8217;,
	//  The values on the left hand side of the colon must match that of the parameters of the webservice
	data: JSON.encode({ value1 : $(&#8216;VALUE1&#8242;).get(&#8216;value&#8217;), value1 : &#8216;VALUE2&#8242; }),
	onSuccess: function (responseJSON, responseText) {
		/*
		DO SOMETHING
		*/
	}
}).send();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/08/mootools-request-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>get all students&#8217; from Serco Facility MSSQL Database</title>
		<link>http://www.andrew-bellamy.co.uk/2010/07/get-all-students-from-serco-facility-mssql-database/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/07/get-all-students-from-serco-facility-mssql-database/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 19:00:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MSSQL]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=244</guid>
		<description><![CDATA[to start // Change connectionString as requried static string connectionString = &#34;Data Source=SERVER;Initial Catalog=DATABASE;User ID=USERNAME;Password=PASSWORD;&#34;; static string sql = &#34;SELECT&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/07/get-all-students-from-serco-facility-mssql-database/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>to start</h4>
<pre class="brush: csharp;">
//  Change connectionString as requried
static string connectionString = &quot;Data Source=SERVER;Initial Catalog=DATABASE;User ID=USERNAME;Password=PASSWORD;&quot;;
static string sql = &quot;SELECT * FROM STUDENTS WHERE SetID = @DataSet&quot;;
</pre>
<h4>the method</h4>
<p>you can use either pieces of code</p>
<h5>code 1</h5>
<pre class="brush: csharp;">
public static object[] GetStudents(string dataset)
{
	ArrayList temp = new ArrayList();

	using (SqlConnection sqlConnection = new SqlConnection(connectionString))
	{
		using (SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection))
		{
			sqlCommand.Parameters.Add(&quot;@DataSet&quot;, SqlDbType.VarChar);
			sqlCommand.Parameters[&quot;@DataSet&quot;].Value = dataset;

			sqlConnection.Open();

			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			int studentID = sqlDataReader.GetOrdinal(&quot;StudentID&quot;);
			int name = sqlDataReader.GetOrdinal(&quot;Name&quot;);
			int classGroupId = sqlDataReader.GetOrdinal(&quot;ClassGroupId&quot;);

			while (sqlDataReader.Read())
			{
				temp.Add(new object[] { sqlDataReader.GetValue(studentID), sqlDataReader.GetValue(name), sqlDataReader.GetValue(classGroupId) });
			}

			sqlConnection.Close();
		}
	}

	return temp.ToArray();
}
</pre>
<h5>code 2</h5>
<pre class="brush: csharp;">
public static DataSet GetStudents(string dataset)
{
	DataSet dataSet;

	using (dataSet = new DataSet())
	{
		using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, connectionString))
		{
			sqlDataAdapter.SelectCommand.Parameters.AddWithValue(&quot;@DataSet&quot;, dataset);
			sqlDataAdapter.Fill(dataSet);
		}
	}

	return dataSet;
}
</pre>
<h4>usage</h4>
<h5>for code 1</h5>
<pre class="brush: csharp;">
static void Main(string[] args)
{
	object[] students = GetStudents(&quot;2010/2011&quot;);
	foreach (object[] student in students)
	{
		Console.WriteLine(student[0] + &quot;~&quot; + student[1] + &quot;~&quot; + student[2]);
	}
}
</pre>
<h5>for code 2</h5>
<pre class="brush: csharp;">
static void Main(string[] args)
{
	using (DataSet dataSet = GetStudents(&quot;2010/2011&quot;))
	{
		foreach (DataRow dataRow in dataSet.Tables[0].Rows)
		{
			Console.WriteLine(dataRow[0] + &quot;~&quot; + dataRow[1] + &quot;~&quot; + dataRow[2]);
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/07/get-all-students-from-serco-facility-mssql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operating System Assignment</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/software-development-i-assignments/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/software-development-i-assignments/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 13:51:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=183</guid>
		<description><![CDATA[This program was created using C# to time the creation of Threads via the Windows API. The users inputs the&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/06/software-development-i-assignments/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<p>This program was created using C# to time the creation of Threads via the Windows API.  The users inputs the amount of threads to create and how many simple calculations the threads perform and then outputs the results.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/OS.zip'>Operating Systems Assignment</a></p>
<p>Download the above file and unzip the contents</p>
<p>Provided in the zip file is the assignment specification and the completed program</p>
<p>Originally written with Visual Studio 2008, updated and written with Visual Studio 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/software-development-i-assignments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Development 3 &#8211; Assignments</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/software-development-3-assignments/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/software-development-3-assignments/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 12:03:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=211</guid>
		<description><![CDATA[Assignment 1, Part A This program, written in C++, is the start of a more complex holiday booking system. This&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/06/software-development-3-assignments/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>Assignment 1, Part A</h4>
<p>This program, written in C++, is the start of a more complex holiday booking system.  This program contains a few classes to hold customers details and contains a test wrapper.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD3-A1-A.zip'>Software Development 3 &#8211; Assignment 1 A</a></p>
<h4>Assignment 1, Part B</h4>
<p>This program adds to the previous assignment by introducing two new classes and inheritance too complete the holiday booking system.  This program also contains test wrappers.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD3-A1-B.zip'>Software Development 3 – Assignment 1 B</a></p>
<h4>Assignment 2</h4>
<p>This program, written in C++, was done using Extreme Programming methodology.  Myself and a partner took it in terns to produce this program; which is a link list applications that loads, saves and allows user input to create a CD collection.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD3-A2.zip'>Software Development 3 – Assignment 2</a></p>
<p>Download the above files and unzip the contents</p>
<p>Provided in the zip files are the assignment specifications and the completed programs</p>
<p>Both written with Visual Studio 2008</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/software-development-3-assignments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Development 2 &#8211; Assignments</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/software-development-2-assignments/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/software-development-2-assignments/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 12:02:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=206</guid>
		<description><![CDATA[Assignment 1 This program, written in C#, displays a schools timetable. Users are able to input timetable details, delete entries,&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/06/software-development-2-assignments/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>Assignment 1</h4>
<p>This program, written in C#, displays a schools timetable.  Users are able to input timetable details, delete entries, save and load the timetable.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD2-1.zip'>Software Development 2 &#8211; Assignment 1</a></p>
<h4>Assignment 2</h4>
<p>This program, written in C#, using Windows Forms (GUI), is a camp site booking system.  Users are able to input new booking, iterate through bookings, delete and update bookings.  Details are automatically saved and loaded from a file.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD2-2.zip'>Software Development 2 &#8211; Assignment 2</a></p>
<p>Download the above files and unzip the contents</p>
<p>Provided in the zip files are the assignment specifications and the completed programs</p>
<p>Both originally written with Visual Studio 2008, updated and written with Visual Studio 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/software-development-2-assignments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Development 1 &#8211; Assignments</title>
		<link>http://www.andrew-bellamy.co.uk/2010/06/software-development-1-assignments-2/</link>
		<comments>http://www.andrew-bellamy.co.uk/2010/06/software-development-1-assignments-2/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 12:01:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.andrew-bellamy.co.uk/?p=199</guid>
		<description><![CDATA[Assignment 1 Simple conversions and measurements program written in C# Software Development I &#8211; Assignment 1 Assignment 2 Based on&#160;[<a href="http://www.andrew-bellamy.co.uk/2010/06/software-development-1-assignments-2/">Read the Rest</a>]]]></description>
			<content:encoded><![CDATA[<h4>Assignment 1</h4>
<p>Simple conversions and measurements program written in C#</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD1-1.zip'>Software Development I &#8211; Assignment 1</a></p>
<h4>Assignment 2</h4>
<p>Based on the dice game &#8220;Drop Dead&#8221;, this program, written in C#, asks the user to enter a number between 5 and 10.  The program then &#8220;roles&#8221; the dice.</p>
<p>If the result of the dice is 2 or 5, that dice is dead and not included in the final calculation.</p>
<p>The remaining dice scores are added together and are the results of the first roll.  This continues until all dice are &#8220;dead&#8221;.  The total score is all the roll scores added together.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD1-2.zip'>Software Development I – Assignment 2</a></p>
<h4>Assignment 3</h4>
<p>This assignment is the Hangman game, written in C#.  An array of words are loaded and one is picked at random by the program.  Users take it in turn to quest a letter or the word.  If the guess is incorrect, the first diagram file is loaded and outputted to the screen.</p>
<p><a href='http://www.andrew-bellamy.co.uk/wp-content/uploads/2010/06/SD1-3.zip'>Software Development I – Assignment 3</a></p>
<p>Download the above files and unzip the contents</p>
<p>Provided in the zip files are the assignment specifications and the completed programs</p>
<p>Both originally written with Visual Studio 2008, updated and written with Visual Studio 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrew-bellamy.co.uk/2010/06/software-development-1-assignments-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
	</channel>
</rss>
