<?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>David Pratt &#187; mysql</title> <atom:link href="http://daipratt.co.uk/tag/mysql/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Thu, 17 May 2012 19:14:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Best way to store IP addresses in MySQL</title><link>http://daipratt.co.uk/mysql-store-ip-address/</link> <comments>http://daipratt.co.uk/mysql-store-ip-address/#comments</comments> <pubDate>Tue, 10 Aug 2010 08:53:35 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[php]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=1258</guid> <description><![CDATA[It's tempting to store IP addresses in a database as a varchar of length 15 in the absence of a dedicated IPv4 field type in mysql, but that isn't the most efficient way of doing so...]]></description> <content:encoded><![CDATA[<p>It&#8217;s tempting to store IP addresses in a database as a VARCHAR(15) in the absence of a dedicated IP address field type in mysql, but that isn&#8217;t the most efficient way of doing so. The best way that I&#8217;ve come across to store an IPv4 address is to store it as an unsigned integer.  In phpmyadmin you might set up an ip address field so that it looks something like:<br
/><div
id="attachment_1264" class="wp-caption alignnone" style="width: 363px"><a
href="http://daipratt.co.uk/wp-content/uploads/2010/08/phpmyadmin-ip-address-setup.png"><img
src="http://daipratt.co.uk/wp-content/uploads/2010/08/phpmyadmin-ip-address-setup.png" alt="Screenshot of the PHPMyAdmin field setup for an IP address field" title="PHPMyAdmin field setup for IP address field" width="353" height="243" class="size-full wp-image-1264" /></a><p
class="wp-caption-text">Screenshot of the PHPMyAdmin field setup for an IP address field</p></div></p><p>You&#8217;ll realise I&#8217;m sure that you can&#8217;t just add the dotted IP address straight into an INT field without first converting it into a valid format.  For that you&#8217;ll need a PHP function called <a
href="http://php.net/manual/en/function.ip2long.php">ip2long</a> which will convert a string containing an IP dotted address into a integer that can be stored in the INT field.</p><p>Here is a quick example of how you might go about getting the real IP address of a client and then storing and retrieving its value from the mysql DB:</p><pre class="brush: php">
//Test if it is a shared client
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  $ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
  $ip=$_SERVER['REMOTE_ADDR'];
}
//The value of $ip at this point would look something like: "192.0.34.166"
$ip = ip2long($ip);
//The $ip would now look something like: 1073732954
</pre><p>Now that you have the real IP address of the client converted to the INT format, you can write it into the DB as you normally would:</p><pre class="brush: php">
$sql = "INSERT INTO user(ip) VALUES('$ip')";
$dbQuery = mysql_query($sql,$dbLink);
</pre><p>To retrieve the original IP address from the database you can use the mysql function <a
href="http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ntoa">INET_NTOA</a> like so:</p><pre class="brush: sql">
SELECT INET_NTOA(ip) FROM 'user' WHERE 1
</pre><p>Alternately you could use the PHP function <a
href="http://www.php.net/manual/en/function.long2ip.php">longtoip</a> to convert the returned INT value into the dotted IPv4 address in the PHP code instead, and you could even add the dotted IP address to the INT field in the db using the mysql funtion INET_ATON.</p><p>Storing IP addresses in this manner is beneficial because it takes less space than storing it as a string.  The other benefit is that lookups are faster because integer comparisons are quicker than string comparisons.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/mysql-store-ip-address/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>Importing large files into mysql with phpmyadmin</title><link>http://daipratt.co.uk/importing-large-files-into-mysql-with-phpmyadmin/</link> <comments>http://daipratt.co.uk/importing-large-files-into-mysql-with-phpmyadmin/#comments</comments> <pubDate>Mon, 18 Jan 2010 12:55:15 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[phpmyadmin]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=1015</guid> <description><![CDATA[A tutorial that explains the steps you need to take in order to import large (2Mb+) SQL files into phpmyadmin]]></description> <content:encoded><![CDATA[<p>I&#8217;m writing this here because it&#8217;s the third time I&#8217;ve had this problem, and the third time I&#8217;ve forgotten how to fix it! If you ever get hit with the error message:</p><div
id="attachment_1018" class="wp-caption alignnone" style="width: 509px"><a
href="http://daipratt.co.uk/wp-content/uploads/2010/01/phpmyadmin.png"><img
src="http://daipratt.co.uk/wp-content/uploads/2010/01/phpmyadmin.png" alt="Phpmyadmin error message" title="phpmyadmin" width="499" height="70" class="size-full wp-image-1018" /></a><p
class="wp-caption-text">“You probably tried to upload too large file. Please refer to documentation for ways to workaround this limit.”</p></div><p>When trying to import large SQL files into mysql using phpmyadmin, the <a
href="http://localhost/phpmyadmin/Documentation.html#faq1_16">phpmyadmin documentation</a> offers a few solutions, but I find the easiest method to overcome this is&#8230;</p><p>Find the <i>config.inc.php</i> file located in the phpmyadmin directory. In my case it is located here:</p><pre class="brush: plain">
C:\wamp\apps\phpmyadmin3.2.0.1\config.inc.php
</pre><p>Find the line with <i>$cfg['UploadDir']</i> on it and update it to:</p><pre class="brush: php">
$cfg['UploadDir'] = 'upload';
</pre><p>Create a directory called &#8216;upload&#8217; within the phpmyadmin directory.</p><pre class="brush: plain">
C:\wamp\apps\phpmyadmin3.2.0.1\upload\
</pre><p>Then place the large sql file that you are trying to import into the new upload directory. Now when you go onto the db import page within phpmyadmin console you will notice a drop down present that wasn&#8217;t there before &#8211; it contains all of the sql files in the upload directory that you have just created.  You can now select this and begin the import.</p><p>If you&#8217;re not using WAMP on Windows, then I&#8217;m sure you&#8217;ll be able to adapt this to your environment without too much trouble.</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/importing-large-files-into-mysql-with-phpmyadmin/feed/</wfw:commentRss> <slash:comments>132</slash:comments> </item> <item><title>How to set up a local server on Windows</title><link>http://daipratt.co.uk/how-to-set-up-a-local-server-on-windows/</link> <comments>http://daipratt.co.uk/how-to-set-up-a-local-server-on-windows/#comments</comments> <pubDate>Mon, 11 May 2009 18:46:33 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[php]]></category> <category><![CDATA[server]]></category> <category><![CDATA[wordpress]]></category> <guid
isPermaLink="false">http://localhost/wordpress/?p=1</guid> <description><![CDATA[Instructions on how to setup a local server manually on a windows box; running Apache, MySQL and PHP.]]></description> <content:encoded><![CDATA[<p>Have you ever wondered how to set up a local server on your windows box running with Apache, MySQL and PHP?  I have. Here&#8217;s how I did it.</p><h3>Mission 1: Download everything</h3><p>Create a folder on your desktop and put the following downloads in it:</p><ul><li><a
href="http://httpd.apache.org/download.cgi">Apache</a> &#8211; <a
href="http://apache.mirror.anlx.net/httpd/binaries/win32/apache_2.2.11-win32-x86-no_ssl.msi">direct</a></li><li><a
href="http://dev.mysql.com/downloads/mysql/5.1.html">MySQL</a> &#8211; Get the windows installer</li><li><a
href="http://www.php.net/downloads.php">PHP</a> &#8211; <a
href="http://uk.php.net/get/php-5.2.8-win32-installer.msi/from/this/mirror">direct</a></li><li><a
href="http://www.libgd.org/Downloads">Module &#8211; GD</a> &#8211; <a
href="http://www.libgd.org/releases/gd-2.0.35.tar.gz">direct</a></li><li><a
href="#">Module &#8211; Mail Server</a> &#8211; <a
href="#">direct</a></li><li><a
href="http://www.phpmyadmin.net/home_page/downloads.php">PHPMyAdmin</a> &#8211; <a
href="http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-3.1.1-english.zip?download#!md5!64f77187056154e044bf9596728127a3">direct</a></li></ul><h3>Mission 2: Install everything with default settings</h3><p>Install the applications in the order that I have listed.</p><p>Apart from PHPMyAdmin. Park that.</p><p>Make sure that you write down with a pen and paper all of your paired usernames and passwords &#8211; you do not want to be in a situation where you end up sitting there wondering whether the default username was root, admin, guest and whether you paired it with your usual password, a special easy one or no password at all!</p><p>So, if you do cock up and can&#8217;t remember your username and password (as I did for MySQL) then you&#8217;ll need to uninstall it with a special tool as the windows one will keep you locked out on reinstall.  You&#8217;ll need <a
href="http://www.revouninstaller.com/revo_uninstaller_free_download.html">Revo univstaller</a> unless you fancying hitting F3 about 50 times in regedit.</p><h3>Mission 3: Configure Apache</h3><p>Unfortunately everything doesn&#8217;t work and play nice straight out of the box. It needs some love (as most things tech do).</p><h4>Enable Apache mod_rewrite module</h4><p>This is the feature that allows sexxy clean urls (permalinks in WordPress) with none of this .php?foo=blah rubbish.</p><ol><li>Open your httpd.conf configuration file (C:Program FilesApache Software FoundationApache2.2confhttpd.conf) with Notepad.</li><li>Remove the # on the #LoadModule rewrite_module modules/mod_rewrite.so line so it becomes LoadModule rewrite_module modules/mod_rewrite.so only.</li><li>Save httpd.conf .</li></ol><h4>Enable AllowOverride for web directory folder (htdocs)</h4><p>This allows the rule set in .htaccess file to over-ride the main one. A bit like upping the specificity in CSS if thats your thing&#8230;</p><ol><li>Open your httpd.conf configuration file (C:Program FilesApache Software FoundationApache2.2confhttpd.conf) with Notepad.</li><li>Under the directory C:Program FilesApache Software FoundationApache2.2htdocs section, change the line that says &#8220;AllowOverride None&#8221; to &#8220;AllowOverride All&#8221;.</li><li>Save your httpd.conf .</li></ol><h3>Mission 4: Create and run info.php</h3><p>Create a file called <strong>info.php</strong>, place it in the directory <span>C:Program FilesApache Software FoundationApache2.2htdocs</span> and put the following code in it:</p><pre class="javascript">&lt;?php
phpinfo();
phpinfo(INFO_MODULES);
?&gt;</pre><p>Now fire up your web browser and type in the url <a
href="http://localhost/info.php">http://localhost/info.php</a> and the page should render with a load of information.  On it you should see that &#8220;rewrite module&#8221; is enabled and gd library is active, zend php is working.</p><h3>Mission 5: Get PHP to talk to MySQL</h3><p>Now that we know PHP works we can configure it to work with MySQL, but first we need to do a quick restart of Apache &#8211; double click on the Apache system tray icon and click restart.</p><p>Next it is time to find PHPMyAdmin.zip you have sitting in that desktop folder, unzip it to this location: C:Program FilesApache Software FoundationApache2.2htdocsphpmyadmin</p><p>Open your browser and navigate to <a
href="http://localhost/phpmyadmin/">http://localhost/phpmyadmin/</a></p><p>Enter all of the details that you wrote down on that piece of paper from earlier.</p><p>And do restart you local Apache web server. Now your can enable the pretty permalink structure from the WordPress dashboard and it will work nicely after that.</p><p>There you have it;  One local server that doesn&#8217;t do a lot. You could have just installed <a
href="http://www.apachefriends.org/en/xampp.html">this</a> if you want the easy option! I&#8217;ll do a follow up post about some of the things that you might want to do with your local server soon&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/how-to-set-up-a-local-server-on-windows/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
