<?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>Adrian Callaghan`s Blog &#187; Work</title>
	<atom:link href="http://adriancallaghan.co.uk/Categorys/work/feed/" rel="self" type="application/rss+xml" />
	<link>http://adriancallaghan.co.uk</link>
	<description>A general mix of everything</description>
	<lastBuildDate>Tue, 10 Jan 2012 12:05:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>session_start hangs when it used to work</title>
		<link>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/</link>
		<comments>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 09:48:35 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=626</guid>
		<description><![CDATA[I had a problem with my zend application hanging with a white screen for no reason. I narrowed it down to when 1 $adminSession = new Zend_Session_Namespace&#40;'Admin'&#41;; was executed, this is just a session? so debugging further, confirmed that session_start() hangs when it used to work. There are lots of explanations for this, but before [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsession_start-hangs-when-it-used-to-work%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>I had a problem with my zend application hanging with a white screen for no reason.<br />
I narrowed it down to when</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$adminSession</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Session_Namespace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>was executed, this is just a session? so debugging further, confirmed that session_start() hangs when it used to work.</p>
<p>There are lots of explanations for this, but before you start modifying ini settings, just try this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">session_write_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I found this resolved the problem completely.<br />
I then just removed this debug-code and went back to developing my zend app.</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsession_start-hangs-when-it-used-to-work%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>database class php</title>
		<link>http://adriancallaghan.co.uk/database-class-php/</link>
		<comments>http://adriancallaghan.co.uk/database-class-php/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 17:05:05 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=615</guid>
		<description><![CDATA[Updated the database class Usage: 1 2 3 4 5 6 &#160; // min instantiation $dataBase = new DB&#40;'hostname','username','password','database'&#41;; &#160; // max instantiation $dataBase = new DB&#40;'hostname','username','password','database',DEBUG_LEVEL,array&#40;'admin@domain.com','admin@domain2.com)); Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fdatabase-class-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Updated the database class </p>
<p>Usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// min instantiation</span>
<span style="color: #000088;">$dataBase</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hostname'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// max instantiation</span>
<span style="color: #000088;">$dataBase</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hostname'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #339933;">,</span>DEBUG_LEVEL<span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin@domain.com'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'admin@domain2.com));</span></pre></td></tr></table></div>

<p>Class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DB<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* 
	 * DESCRIPTION:		Object class, Handles all database requests and returns content accordingly
	 * WRITER:			Adrian Callaghan 12,08,08      
	 * UPDATED: 		Adrian Callaghan 08,08,11
	 * 
	 * 
	 * errLvl 
	 * 		(0), none, 
	 * 		(1) show a user error, 
	 * 		(2) (1) + mysql error
	 * 		(3) (2) + show a full error (mysql errors), 
	 * 		(4) (3) + plus debugging 
	*/</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mySqlHost</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataBase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$emailAddresses</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$adminEmails</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Sets up a new connection
		 */</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// MIN required</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHost</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPwd</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pwd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setErrLvl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// sets defualt RTE</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEmailErrsTo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adminEmails</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// connect</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDb</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
 	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 		<span style="color: #666666; font-style: italic;">/*
 		 * Close the connection
 		 */</span>
 		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setHost<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the hostname
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">host</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$host</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
 	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setUsr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$usr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the username
		 */</span>
 		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setPwd<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pwd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the password
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pwd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setErrLvl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errLvl</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the error reporting level
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Connect to server
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pwd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</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;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot connect to server'</span><span style="color: #339933;">,</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: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * closes current connection
		 */</span> 
		<span style="color: #339933;">@</span><span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setDb<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Set the database
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBase</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBase</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;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot select database'</span><span style="color: #339933;">,</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: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setEmailErrsTo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// ensure it is an array</span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if empty return</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// assign the email addresses</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> getQuery<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: #666666; font-style: italic;">// executes a query</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</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><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</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;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// create a 2D array of results</span>
		<span style="color: #000088;">$return</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: #339933;">;</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_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$return</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: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> setQuery<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: #666666; font-style: italic;">// executes a query without returning any results, used for insert, create etc, returns the ID of the last auto-increment</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</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><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</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;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SQL</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Handles errors
		 * 
		 */</span>
&nbsp;
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>	<span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kill the mysql output</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>	<span style="color: #000088;">$SQL</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kill the sql output</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span> 
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">:</span> 
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1 style='color:#444444;'&gt;<span style="color: #006699; font-weight: bold;">$message</span>&lt;/h1&gt;&lt;hr&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">!==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;span style='color:#ff0000; font-weight:bold;'&gt;Mysql: &lt;/span&gt;<span style="color: #006699; font-weight: bold;">$mysqlErr</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">!==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;span style='color:#ff0000; font-weight:bold;'&gt;Whole query: &lt;/span&gt;<span style="color: #006699; font-weight: bold;">$SQL</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>			
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
 		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateEmail</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Mysql'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Sql'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Err Level'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 		<span style="color: #666666; font-style: italic;">// three is for debugging</span>
 		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$sent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendEmails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sent</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;The administrator has been notified&lt;/h2&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Please notify the administrator'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;'s &quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' or '</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> generateEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'Server name'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'Query'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'Ip'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_PORT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'@'</span><span style="color: #339933;">=&gt;</span>date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D dS M,Y h:i a&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
		<span style="color: #000088;">$rtn</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;table bgcolor=&quot;#cccccc&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$title</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$rtn</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td bgcolor='#aaaaaa'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/td&gt;&lt;td bgcolor='#bbbbbb'&gt;<span style="color: #006699; font-weight: bold;">$value</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$rtn</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sendEmails<span style="color: #009900;">&#40;</span><span style="color: #000088;">$reciptents</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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// email message</span>
		<span style="color: #000088;">$Name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//senders name </span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;noreply@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//senders e-mail adress </span>
&nbsp;
		<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Error&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//subject </span>
&nbsp;
		<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-type: text/html; charset=iso-8859-1'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>		
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;From: &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$Name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &lt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #000088;">$success</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</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;">emailAddresses</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$admin_email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sent</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$admin_email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mail_body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sent</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$success</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// holds state for any email being succesfully sent</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$success</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fdatabase-class-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/database-class-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>compile your own lamp stack with mysqli</title>
		<link>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/</link>
		<comments>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 10:44:21 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=596</guid>
		<description><![CDATA[Install LAMP with one line One liner sudo apt-get install lamp-server^ Add CURL and enable mod-rewrite sudo apt-get install php5-curl sudo a2enmod rewrite To compile LAMP with mysqli and mysql Assuming you have a fresh clean minimal install of ubuntu start by install gcc and wget sudo apt-get gcc sudo apt-get wget Download apache and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fcompile-your-own-lamp-stack-with-mysqli%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<h2>Install LAMP with one line</h2>
<p>One liner</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lamp-server^</pre></div></div>

<p>Add CURL and enable mod-rewrite</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-curl
<span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod rewrite</pre></div></div>

<h2>To compile LAMP with mysqli and mysql</h2>
<p>Assuming you have a fresh clean minimal install of ubuntu start by install gcc and wget</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">wget</span></pre></div></div>

<p>Download <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=596&Ck_lnk=http://httpd.apache.org/">apache</a> and <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=596&Ck_lnk=http://www.php.net/downloads.php">php</a> and use filezilla or a similar SFTP client to upload them to the server (I was unable to find a direct link that didnt pass through a mirror), once uploaded move to the directory on the cmd line.</p>
<p>unpack apache</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-d</span> httpd-<span style="color: #000000;">2</span>_x_NN.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xf</span> httpd-<span style="color: #000000;">2</span>_x_NN.tar</pre></td></tr></table></div>

<p>unpack PHP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-d</span> php-NN.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xf</span> php-NN.tar</pre></td></tr></table></div>

<p>Compile and install Apache</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> httpd-<span style="color: #000000;">2</span>_x_NN
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-so</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Compile PHP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>php-NN
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd</pre></td></tr></table></div>

<p>This will fail with an error &#8220;error locating libxml2&#8243; fix this with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2</pre></div></div>

<p>Next the error below will appear</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xml2 config not found Please check your libxml2 installation</pre></div></div>

<p>Point your browser or ftp client at ftp://xmlsoft.org/libxml2/ and take note of the latest version for libxml2-2.6.28 and then grab it and install it from the server</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>xmlsoft.org<span style="color: #000000; font-weight: bold;">/</span>libxml2<span style="color: #000000; font-weight: bold;">/</span>libxml2-<span style="color: #000000;">2</span>.X.XX.tar.gz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> libxml2-<span style="color: #000000;">2</span>.X.XX.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> libxml2-<span style="color: #000000;">2</span>.X.XX<span style="color: #000000; font-weight: bold;">/</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Try to compile PHP again:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd</pre></td></tr></table></div>

<p>next problem is Mysql</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">configure: error: Cannot <span style="color: #c20cb9; font-weight: bold;">find</span> MySQL header files under <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config</pre></div></div>

<p>To fix this, Install mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server</pre></div></div>

<p>But now even though Mysql is found there are still no headers so first install php module for mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-mysql</pre></div></div>

<p>and add the header library</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmysqlclient15-dev</pre></div></div>

<p>Now PHP should compile and install fine:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Set up an ini file for PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> php.ini-development <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>tell apache to load the module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadModule php5_module modules<span style="color: #000000; font-weight: bold;">/</span>libphp5.so</pre></div></div>

<p>You need to re/start apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apachectl start</pre></div></div>

<p> personally I like to restart the entire server with changes this big</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">shutdown now <span style="color: #660033;">-r</span></pre></div></div>

<p>Thats it!</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fcompile-your-own-lamp-stack-with-mysqli%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>simple mvc</title>
		<link>http://adriancallaghan.co.uk/simple-mvc/</link>
		<comments>http://adriancallaghan.co.uk/simple-mvc/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 13:18:47 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=579</guid>
		<description><![CDATA[Need a lightweight, fast, php mvc framework? I have written a small framework named &#8220;Simple MVC&#8221; it does exactly what it says on the box, its quick to install and can be configured to handle most tasks. Once the file is unzipped you will be presented with this structure: Simply upload the whole structure, and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsimple-mvc%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Need a lightweight, fast, php mvc framework?</p>
<p>I have written a small framework named &#8220;<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">Simple MVC</a>&#8221; it does exactly what it says on the box, its quick to install and can be configured to handle most tasks.</p>
<p>Once the file is unzipped you will be presented with this structure:<br />
<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/uploads/2010/08/layout.jpg"><img src="http://adriancallaghan.co.uk/wp-content/uploads/2010/08/layout.jpg" alt="" title="layout" width="211" height="129" class="alignnone size-full wp-image-580" /></a></p>
<p>Simply upload the whole structure, and the framework will work.</p>
<p>It is designed to be very fast and lightweight, however it can be configured, opening the file mvc_env.php within the &#8220;<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">Simple MVC</a>&#8221; folder displays the following preferences:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">/*
 * 
 * Simple MVC settings file (this file does not need to be present)
 * Examples of different settings are contained here, just uncomment to use
 * 
 * By Adrian Callaghan 300810
 * 
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// error controller</span>
<span style="color: #666666; font-style: italic;">// defines a controller to handle errors, namely the page not found</span>
<span style="color: #666666; font-style: italic;">// the controller is automatically exempt from an actual page request</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;error['controller']='error';
$env-&gt;error['view']='index';
$env-&gt;error['pageNotFoundAction']='pageNotFound';
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// routerMap</span>
<span style="color: #666666; font-style: italic;">// holds controller and action mappings to different controller, action (comma delimited)</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;routerMap['foo,bar']='index,index';
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// routerDeny</span>
<span style="color: #666666; font-style: italic;">// holds controller and action mappings to deny (comma delimited)</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;routerDeny[]='controller,action'; // will deny the page /controller/action/
$env-&gt;routerDeny[]=''; // will deny homepage
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// prelayout</span>
<span style="color: #666666; font-style: italic;">// defines an array of elements to be included before the main view</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;prelayout = array('header');
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// postlayout</span>
<span style="color: #666666; font-style: italic;">// defines an array of elements to be included after the main view</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;postlayout = array('sidebar','footer');
*/</span></pre></td></tr></table></div>

<p>As you can see, page routing, error controllers, page denials etc can all be added here.</p>
<p>The whole framework is just one file and the source looks like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * 
 * Simple MVC 
 * 
 * By Adrian Callaghan 300810
 * 
 */</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// enviroment</span>
<span style="color: #000088;">$env</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// url mapping</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'relative'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../application/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'__url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// mvc</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// settings</span>
<span style="color: #339933;">@</span><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mvc_env.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tell the controllers where to load models from</span>
<span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$env</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>models/<span style="color: #006699; font-weight: bold;">$class_name</span>.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// add custom error controller to list of denys</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// mapping</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>,<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>,<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the controller</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// unset the controller if this is a denied resource, this is done on URL only, so not to interfere with any mappings</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">// if neither the controller or action was found set an error for the error controller to handle</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// can we run the error handler?</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pageNotFoundAction'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #339933;">@</span><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h1&gt;Fatal error&lt;/h1&gt;Missing action: &lt;b&gt;<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&lt;/b&gt; in controller: &lt;b&gt;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>&lt;/b&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// output will be handled by the dispatcher below	</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// if we do not even have an error handler, throw a traditional 404 and die</span>
		<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
		&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
		&lt;h1&gt;Not Found&lt;/h1&gt;
		&lt;p&gt;The requested URL <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> was not found on this server.&lt;/p&gt;
		&lt;/body&gt;&lt;/html&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// dispatcher /////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//attempt to execute the action in the controller,</span>
<span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">// check to see if the view has been altered</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set up the content and view</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prelayout</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;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prelayout</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">$element</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">{$env-&gt;view}</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postlayout</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;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postlayout</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">$element</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>A helloworld quickstart can be downloaded from <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">here</a></p>
<p>The helloworld also has examples of where to instaniate the models, and how to redirect the view in the comments.
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsimple-mvc%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/simple-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sort a array by its value</title>
		<link>http://adriancallaghan.co.uk/sort-a-array-by-its-value/</link>
		<comments>http://adriancallaghan.co.uk/sort-a-array-by-its-value/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 12:45:07 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=577</guid>
		<description><![CDATA[To sort an array by its value, similiar to mysql sort by just use 1 usort&#40;$array, create_function&#40;'$a, $b, $sortBy=&#34;distance&#34;', 'return strnatcmp($a[$sortBy], $b[$sortBy]);'&#41;&#41;; $array stores the array $sortBy set the key to sort by i.e 1 2 3 4 5 6 7 $array = array &#40; 1=&#62;array&#40;'name'=&#62;'me','location'=&#62;'somewhere','distance'=&#62;'200'&#41;, 2=&#62;array&#40;'name'=&#62;'you','location'=&#62;'somewhere','distance'=&#62;'2'&#41; &#41;; &#160; usort&#40;$array, create_function&#40;'$a, $b, $sortBy=&#34;distance&#34;', 'return strnatcmp($a[$sortBy], [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsort-a-array-by-its-value%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>To sort an array by its value, similiar to mysql sort by just use</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$a, $b, $sortBy=&quot;distance&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strnatcmp($a[$sortBy], $b[$sortBy]);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>$array stores the array<br />
$sortBy set the key to sort by</p>
<p>i.e</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #cc66cc;">1</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'me'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'somewhere'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'distance'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #cc66cc;">2</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'you'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'somewhere'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'distance'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$a, $b, $sortBy=&quot;distance&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strnatcmp($a[$sortBy], $b[$sortBy]);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>will result in the array being re-ordered with location 2 now being in location 1 (preserving the keys)</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsort-a-array-by-its-value%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/sort-a-array-by-its-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress comment count as a button</title>
		<link>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/</link>
		<comments>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 13:46:56 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=533</guid>
		<description><![CDATA[Styling the wordpress comment count as a button/icon etc can be tricky because the normal call to the comments 1 comments_popup_link&#40;__&#40;'Comments (0)'&#41;, __&#40;'Comments (1)'&#41;, __&#40;'Comments (%)'&#41;&#41;; formats the output as an anchor point with the correct link, alt tags etc already set up. So in order to intercept this and then add you own anchor [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fwordpress-comment-count-as-a-button%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Styling the wordpress comment count as a button/icon etc can be tricky because the normal call to the comments</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">comments_popup_link<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (0)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (1)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (%)'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>formats the output as an anchor point with the correct link, alt tags etc already set up.</p>
<p>So in order to intercept this and then add you own anchor point with divs/imagery etc you need to make a custom request</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// SQL</span>
<span style="color: #000088;">$SQL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(*) AS Count FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span> WHERE comment_approved='1'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SQL</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_post_ID='&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sort the array into a string prefixed with 'Comments '</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">,</span> ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
<span style="color: #000088;">$comments</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Comments ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// generate the alt and title tags</span>
<span style="color: #000088;">$alt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Comment on '</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// echo the button if this is not a single and not a page</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// anchor open</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$alt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$alt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// complex formatting rules for the comment pop up, go here</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$comments</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// anchor close</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above does exactly the same, formats the link etc, but now you can access the anchor point directly and format it your own way.</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fwordpress-comment-count-as-a-button%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ftp open in explorer by default in windows</title>
		<link>http://adriancallaghan.co.uk/ftp-open-in-explorer-by-default-in-windows/</link>
		<comments>http://adriancallaghan.co.uk/ftp-open-in-explorer-by-default-in-windows/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 09:25:24 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=527</guid>
		<description><![CDATA[How to make explorer open by default when opening an ftp connection, I found can be easy.. I needed to make IE6 style FTP access without the extra pop up step, from a desktop shortcut at work and after much googling, and messing with the registery, attempting to make an ftp site open immediatly in [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fftp-open-in-explorer-by-default-in-windows%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>How to make explorer open by default when opening an ftp connection, I found can be easy..</p>
<p>I needed to make IE6 style FTP access without the extra pop up step, from a desktop shortcut at work and after much googling, and messing with the registery, attempting to make an ftp site open immediatly in explorer without the main browser opening (pre IE7), I found it can be simply done like this.</p>
<p>1. create a bat file (open notepad, save the file with the affix .bat, making sure .txt is not selected in the dropdown)<br />
2. in the batch file add</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="dos" style="font-family:monospace;">start explorer ftp://USERNAME:PASSWORD<span style="color: #33cc33;">@</span>FTP_SERVER_ADDRESS</pre></td></tr></table></div>

<p>3. add the shortcut to the desktop, and style the icon</p>
<p>Now when the user clicks the shortcut, voila IE6 style FTP access without the extra step, much easier than poking around with the registery <img src='http://adriancallaghan.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fftp-open-in-explorer-by-default-in-windows%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/ftp-open-in-explorer-by-default-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0 in $_GET is empty in PHP</title>
		<link>http://adriancallaghan.co.uk/zero-tolerance-for-zero-in-php/</link>
		<comments>http://adriancallaghan.co.uk/zero-tolerance-for-zero-in-php/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 20:39:24 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=119</guid>
		<description><![CDATA[Whilst at work, I was writing a cart for an e-commerce site I am building. The Cart consisted of a multi-dimensioned array, part associative, part indexed, anyway of note here is that, A. It was an array. B. The contents where indexed numerically C. Arrays as you know begin at zero. When removing an element [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fzero-tolerance-for-zero-in-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Whilst at work, </p>
<p>I was writing a cart for an e-commerce site I am building.</p>
<p>The Cart consisted of a multi-dimensioned array, part associative, part indexed, anyway of note here is that,</p>
<p>A. It was an array.<br />
B. The contents where indexed numerically<br />
C. Arrays as you know begin at zero.</p>
<p>When removing an element from the cart, the elements indexed value, is passed via GET to be handled via the object, for removal.</p>
<p>It seemed to work fine, until I attempted to remove the first element, after a little debugging, I noticed the &#8220;0&#8243; value was being interpreted by PHP as empty?</p>
<p>WTF?</p>
<p>A quick mock up code later</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'get'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;I RECIEVED A GET WITH VALUE: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'get'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>and a check in the url </p>
<p>nameOfFile.php?get=1   displayed &#8220;I RECIEVED A GET WITH VALUE: 1&#8243;<br />
nameOfFile.php?get=0   displayed &#8220;&#8221;</p>
<p>It seems that according to PHP the value zero is interpreted as empty because it is being handled as a string when used within GET.</p>
<p>But&#8230;&#8230;&#8230;&#8230;&#8230;.</p>
<p>A string, as the name suggests is just a string of characters, strung together, it is an array of characters, or bytes, the fact that it held zero, would be irrelevant would`nt it not?</p>
<p>I can understand if it was attempting to cast the datatype to an integer, but again, zero is still zero.</p>
<p>The only scenerio I can see this being valid if it where NULL!</p>
<p>PHP uses loose datatypes or lucid?
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fzero-tolerance-for-zero-in-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/zero-tolerance-for-zero-in-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adrian Callaghan`s graduation</title>
		<link>http://adriancallaghan.co.uk/graduation-footage/</link>
		<comments>http://adriancallaghan.co.uk/graduation-footage/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 21:16:31 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[LinkedIn]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=48</guid>
		<description><![CDATA[  This is recent footage from the graduation ceremony, I have edited out all the boring stuff, so only about 20sec`s remains. It was a lovely day, and I am glad I attended..]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fgraduation-footage%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=48&Ck_lnk=http://adriancallaghan.co.uk/wp-content/uploads/2008/10/TITLE01.wmv"></a></p>
<p style="text-align: center;"> <object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="300" height="300" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"><param name="autostart" value="false" /><param name="name" value="Adrians graduation" /><param name="url" value="http://adriancallaghan.co.uk/wp-content/uploads/2008/10/me.wmv" /><embed type="application/x-mplayer2" width="300" height="300" url="http://adriancallaghan.co.uk/wp-content/uploads/2008/10/me.wmv" autostart="false" name="Adrians graduation"></embed></object></p>
<p>This is recent footage from the graduation ceremony, I have edited out all the boring stuff, so only about 20sec`s remains.</p>
<p>It was a lovely day, and I am glad I attended..
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fgraduation-footage%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/graduation-footage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

