<?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>klkl &#187; PHP</title>
	<atom:link href="http://klkl.co.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://klkl.co.uk</link>
	<description>it's easy to type</description>
	<lastBuildDate>Sun, 11 Apr 2010 13:40:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Connecting to MySQL Over SSH</title>
		<link>http://klkl.co.uk/2010/03/21/connecting-to-mysql-over-ssh/</link>
		<comments>http://klkl.co.uk/2010/03/21/connecting-to-mysql-over-ssh/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 14:06:56 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[tunnel]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=251</guid>
		<description><![CDATA[<p>The last couple of days I&#8217;ve been thinking about setting up a local copy of my websites on my laptop so that I can develop them before I make them live.</p>
<p>Last night I enabled PHP on the apache server built into Mac OSX on my new laptop and installed MySQL on it. I also set up some bash aliases to rsync commands so that I could synchronise the websites from the server to the laptop and back again.</p>
<p>Now that I had local copies of the sites that are synchronised it was time to turn my attention to synchronising the databases between the server and my local machine. I could of configured the server&#8217;s MySQL installation to allow remote connections, however, I did not want to do this for security reasons. I decided that I would connect to the MySQL server over SSH by forwarding a port on my local machine to a remote port on the server.</p>
<p>First I needed to create an SSH tunnel using the following command</p>
<p style="padding-left: 30px;">ssh -fNg -L 3307:127.0.0.1:3306 server.host.name<span id="more-251"></span></p>
<p>The options for SSH are</p>
<ul>
<li>f
<ul>
<li>Requests SSH to background so that you do not have to keep a terminal connected to the server open</li>
</ul>
</li>
<li>N
<ul>
<li>Does not execute a remote command (useful for just forwarding ports)</li>
</ul>
</li>
<li>g
<ul>
<li>Allows remote hosts to connect to local forwarded ports</li>
</ul>
</li>
<li>L
<ul>
<li>Specifies that a local port (3307) is forwarded to the given host (server.host.name) and port (3306)</li>
</ul>
</li>
</ul>
<p>I created an alias to that command for easy use in future but I&#8217;ll need to make sure the tunnel is active before trying to connect to the remote server.</p>
<p>Next its time to turn our attention to actually connecting to the remote MySQL server.</p>
<p style="padding-left: 30px;">mysql -h 127.0.0.1 -P 3307 -u username -p</p>
<p>The Options:</p>
<ul>
<li>h specifies the host to connect to (must be 127.0.0.1)</li>
<li>P specifies the port to connect to (your locally forwarded port)</li>
<li>u specifies the username to connect with</li>
<li>p will prompt you for your password (&#8211;password=passtext can be used to give the password)</li>
</ul>
<p>Thats if I wanted to connect to the remote MySQL server on the command line. The latest phpmyadmin has an option for syncronizing databases in which case you can put the above details and it will compare the databases and allow you to choose what to synchronise.</p>
]]></description>
			<content:encoded><![CDATA[<p>The last couple of days I&#8217;ve been thinking about setting up a local copy of my websites on my laptop so that I can develop them before I make them live.</p>
<p>Last night I enabled PHP on the apache server built into Mac OSX on my new laptop and installed MySQL on it. I also set up some bash aliases to rsync commands so that I could synchronise the websites from the server to the laptop and back again.</p>
<p>Now that I had local copies of the sites that are synchronised it was time to turn my attention to synchronising the databases between the server and my local machine. I could of configured the server&#8217;s MySQL installation to allow remote connections, however, I did not want to do this for security reasons. I decided that I would connect to the MySQL server over SSH by forwarding a port on my local machine to a remote port on the server.</p>
<p>First I needed to create an SSH tunnel using the following command</p>
<p style="padding-left: 30px;">ssh -fNg -L 3307:127.0.0.1:3306 server.host.name<span id="more-251"></span></p>
<p>The options for SSH are</p>
<ul>
<li>f
<ul>
<li>Requests SSH to background so that you do not have to keep a terminal connected to the server open</li>
</ul>
</li>
<li>N
<ul>
<li>Does not execute a remote command (useful for just forwarding ports)</li>
</ul>
</li>
<li>g
<ul>
<li>Allows remote hosts to connect to local forwarded ports</li>
</ul>
</li>
<li>L
<ul>
<li>Specifies that a local port (3307) is forwarded to the given host (server.host.name) and port (3306)</li>
</ul>
</li>
</ul>
<p>I created an alias to that command for easy use in future but I&#8217;ll need to make sure the tunnel is active before trying to connect to the remote server.</p>
<p>Next its time to turn our attention to actually connecting to the remote MySQL server.</p>
<p style="padding-left: 30px;">mysql -h 127.0.0.1 -P 3307 -u username -p</p>
<p>The Options:</p>
<ul>
<li>h specifies the host to connect to (must be 127.0.0.1)</li>
<li>P specifies the port to connect to (your locally forwarded port)</li>
<li>u specifies the username to connect with</li>
<li>p will prompt you for your password (&#8211;password=passtext can be used to give the password)</li>
</ul>
<p>Thats if I wanted to connect to the remote MySQL server on the command line. The latest phpmyadmin has an option for syncronizing databases in which case you can put the above details and it will compare the databases and allow you to choose what to synchronise.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2010/03/21/connecting-to-mysql-over-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Equivalent to the SQL IN (&#8230;) Statement</title>
		<link>http://klkl.co.uk/2009/07/18/php-equivalent-to-the-sql-in-statement/</link>
		<comments>http://klkl.co.uk/2009/07/18/php-equivalent-to-the-sql-in-statement/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 13:21:28 +0000</pubDate>
		<dc:creator>klkl</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Pharmacy]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[dm+d]]></category>
		<category><![CDATA[NHS]]></category>
		<category><![CDATA[nhsbsa]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://klkl.co.uk/?p=203</guid>
		<description><![CDATA[<p>Recently I&#8217;ve been looking at using the NHS Business Service Authority&#8217;s Dictionary of Medicines and Devices for my own nefarious purposes. The Information (data that has meaning) is distributed as XML files.</p>
<p>I haven&#8217;t come across a database design for the data so I&#8217;ve come up with my own and to import the data into it I&#8217;ve been using PHP&#8217;s XML DOM functionality (<a title="Parse XML in PHP" href="http://klkl.co.uk/2007/10/23/how-to-parse-an-xml-file-using-php-part-1/" target="_blank">a different technique than I described in my earlier post &#8230;</a>). Because the files are published according to specified standards I decided to save myself some programming time by adopting their terminology for my database design so that I could write very little code to prepare the data and insert it into the database.</p>
<p>However, I wanted to test that the nodes I was expecting were what was being prepared for insertion into the database. One reason it may not is if the XML file has been reformatted with indents (<a title="HowTo Quickly Indent XML" href="http://klkl.co.uk/2009/07/14/how-to-indent-xml-quickly/" target="_blank">mentioned in this post</a>) What I needed was an equivalent to SQLs IN statement. The solution is to use PHP&#8217;s in_array() function like so&#8230;</p>
<p style="padding-left: 30px;"><strong>$desirable_values = array(&#8217;CD&#8217;, &#8216;CDDT&#8217;, &#8216;CDPREV&#8217;, &#8216;DESC&#8217;);<br />
if ( in_array( $variable_to_test, $desirable_values) ) {<br />
//Do Your Stuff<br />
}</strong></p>
<p>It saves you having to test if your variable is equal to each of the variables you want to test thus making your code cleaner and shorter.</p>
]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been looking at using the NHS Business Service Authority&#8217;s Dictionary of Medicines and Devices for my own nefarious purposes. The Information (data that has meaning) is distributed as XML files.</p>
<p>I haven&#8217;t come across a database design for the data so I&#8217;ve come up with my own and to import the data into it I&#8217;ve been using PHP&#8217;s XML DOM functionality (<a title="Parse XML in PHP" href="http://klkl.co.uk/2007/10/23/how-to-parse-an-xml-file-using-php-part-1/" target="_blank">a different technique than I described in my earlier post &#8230;</a>). Because the files are published according to specified standards I decided to save myself some programming time by adopting their terminology for my database design so that I could write very little code to prepare the data and insert it into the database.</p>
<p>However, I wanted to test that the nodes I was expecting were what was being prepared for insertion into the database. One reason it may not is if the XML file has been reformatted with indents (<a title="HowTo Quickly Indent XML" href="http://klkl.co.uk/2009/07/14/how-to-indent-xml-quickly/" target="_blank">mentioned in this post</a>) What I needed was an equivalent to SQLs IN statement. The solution is to use PHP&#8217;s in_array() function like so&#8230;</p>
<p style="padding-left: 30px;"><strong>$desirable_values = array(&#8217;CD&#8217;, &#8216;CDDT&#8217;, &#8216;CDPREV&#8217;, &#8216;DESC&#8217;);<br />
if ( in_array( $variable_to_test, $desirable_values) ) {<br />
//Do Your Stuff<br />
}</strong></p>
<p>It saves you having to test if your variable is equal to each of the variables you want to test thus making your code cleaner and shorter.</p>
]]></content:encoded>
			<wfw:commentRss>http://klkl.co.uk/2009/07/18/php-equivalent-to-the-sql-in-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
