<?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>ria-coder.com &#187; MySQL</title>
	<atom:link href="http://ria-coder.com/blog/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://ria-coder.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 21 Apr 2010 19:35:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>AMFPHP Genie v0.2</title>
		<link>http://ria-coder.com/blog/amfphp-genie-02</link>
		<comments>http://ria-coder.com/blog/amfphp-genie-02#comments</comments>
		<pubDate>Sun, 13 Dec 2009 23:35:56 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[amfphp genie]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=505</guid>
		<description><![CDATA[AMFPHP Genie (0.2) is a simple tool to help you get shit done using Flex and AMFPHP.]]></description>
			<content:encoded><![CDATA[<p>AMFPHP Genie (0.2) is a simple tool to help you get shit done using Flex and AMFPHP.</p>
<p>Check out <a title="AMFPHP Genie" href="http://dannykopping.co.za/amfphp-genie/">http://dannykopping.co.za/amfphp-genie/</a> for more information!</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/amfphp-genie-02/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>QuickTip: asSQL Connection Problem with non-localhost hostname</title>
		<link>http://ria-coder.com/blog/assql-connection-problem-with-non-localhost-hostname</link>
		<comments>http://ria-coder.com/blog/assql-connection-problem-with-non-localhost-hostname#comments</comments>
		<pubDate>Sat, 12 Dec 2009 22:58:26 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[assql]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=488</guid>
		<description><![CDATA[Read this post to fix that annoying error with asSQL when trying to connect to remote MySQL installations]]></description>
			<content:encoded><![CDATA[<p><a title="asSQL" href="http://code.google.com/p/assql/">asSQL</a> is just great. It&#8217;s an ActionScript 3.0 library  for connecting AIR applications to MySQL databases and it works brilliantly &#8211; when it works! Recently i gave it a shot again after an utter failure the last time i tried it&#8230; The library seems to be a port of the Java implementation of connecting to MySQL (<em>Connections, Statements, Fields, etc</em>). It takes a little getting used to but it&#8217;s an excellent library and i highly recommend it.<br />
<br />
<h2>Background</h2>
<p>My development environment is Windows-based (against my wishes&#8230; not enough loot or motivation for a Mac, lack of Adobe software on Linux) but i make up for this by running a virtual Linux installation in my Windows environment and networking the two together. It actually works really well, and the process for setting this up can be found <a title="Ubuntu + Windows" href="http://www.simonholywell.com/computing/internet/a-good-windows-development-environment-and-ubuntu-virtualbox.html">here</a>. To cut a very long and boring story short, essentially i cannot use <em>localhost</em> as your server when using this architecture since i have my LAMPP stack running on my Linux environment, so my &#8220;local server&#8221; can only be accessed using the IP address of the virtual system.</p>
<p>This complicates things a bit when trying to use asSQL to connect to my MySQL installation, because MySQL gets all paranoid and won&#8217;t accept connections from a foreign IP address (the IP of my Windows machine on which my AIR app is running)&#8230; To get around this, all you have to do is create a new user in MySQL (i used <a title="phpMyAdmin" href="http://phpmyadmin.net">phpMyAdmin</a>), set the user&#8217;s hostname to the IP address of your remote system (i&#8217;ve explained how to do this below) and you&#8217;re ready to rock and roll!<br />
<br />
<h2>Solution</h2>
<p>The first thing you need to do is get the IP address of the remote system&#8230;</p>
<p><strong>Windows: </strong>Open the command line, type <em>ipconfig<br />
<strong><span style="font-style: normal;">Linux</span><span style="font-weight: normal;"> </span><span style="font-style: normal;">&amp; Mac: <span style="font-weight: normal;">Open the terminal, type <em>ifconfig</em></span></span></strong></em></p>
<p><strong><span style="font-weight: normal;">In this example, my IP address is </span>192.168.56.1</strong></p>
<p>I&#8217;ll be using phpMyAdmin to fix the problem.</p>
<ol>
<li>Open phpMyAdmin and click on the <strong>Privileges</strong> tab.</li>
<li>Click <strong>Add a new User</strong></li>
<li>Enter any username you like, paste the IP address obtained in the <strong>Host</strong> field and put in a password</li>
<li>Under the <em>Database for user</em> panel, leave it at <strong>None</strong></li>
<li>Under the <em>Global privileges</em>, you can <strong>Check All</strong></li>
</ol>
<p>That should sort it out&#8230; Remember, this is <strong>HIGHLY</strong> insecure and should <strong>only be used on development environments and <span style="text-decoration: underline;">NOT</span> production environments.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/assql-connection-problem-with-non-localhost-hostname/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Conditional Statements with MySQL</title>
		<link>http://ria-coder.com/blog/using-conditional-statements-with-mysql</link>
		<comments>http://ria-coder.com/blog/using-conditional-statements-with-mysql#comments</comments>
		<pubDate>Thu, 14 May 2009 19:36:59 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[conditionals]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=276</guid>
		<description><![CDATA[While working on a project, i got lazy (as i always do...); I didn't feel like fetching an array of rows from MySQL and filtering the data in PHP according to a condition...]]></description>
			<content:encoded><![CDATA[<p>While working on a project, i got lazy (as i always do&#8230;); I didn&#8217;t feel like fetching an array of rows from MySQL and filtering the data in PHP according to a condition&#8230; Too much of a ballache to be honest. I thought: &#8216;<em>F</em><em>uck it&#8230; Let&#8217;s see if one can use conditional statements in MySQL</em>&#8216;<em>.</em></p>
<p>After doing a little research, i came across this page (<a title="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html" href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html" target="_blank">http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html</a>). After scouring through the normally indecipherable MySQL reference manual, i managed to get the hang of it&#8230;</p>
<p>Although the scenarios where the application of this functionality are few and far between, i felt it&#8217;d still be a cool idea to share this (seemingly) arbitrary tit-bit.</p>
<p>Consider the following scenario&#8230;<br />
You have a table of users. In this table, you keep the following information about each user:</p>
<blockquote>
<ul>
<li>name</li>
<li>surname</li>
<li>gender</li>
</ul>
</blockquote>
<p>Now, depending on the gender of your user, you would like to return their details with a certain prefix, namely <strong>Mr </strong>for a male or <strong>Ms</strong> for a female. Here&#8217;s the database structure, and two rows of sample data:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`users`</span>
<span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`surname`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`gender`</span> enum<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'M'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'F'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1 ROW_FORMAT<span style="color: #66cc66;">=</span>DYNAMIC;
&nbsp;
<span style="color: #808080; font-style: italic;">--</span>
<span style="color: #808080; font-style: italic;">-- Sample data</span>
<span style="color: #808080; font-style: italic;">--</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`users`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`surname`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`gender`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Joe'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Shmo'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'M'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Jane'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Shmane'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'F'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>&#8230;and here&#8217;s the SQL query</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*,</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>gender <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;M&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Mr &quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Ms &quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">,</span> surname<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AS</span> fullName
<span style="color: #993333; font-weight: bold;">FROM</span> users</pre></div></div>

<p>If that looks a little too indecipherable/complicated, here&#8217;s the previous query in a more simplified (albeit less efficient) way:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*,</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>gender <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;M&quot;</span><span style="color: #66cc66;">,</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Mr &quot;</span><span style="color: #66cc66;">,</span> name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">,</span> surname<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
			CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Ms &quot;</span><span style="color: #66cc66;">,</span> name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">,</span> surname<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AS</span> fullName
<span style="color: #993333; font-weight: bold;">FROM</span> users</pre></div></div>

<p><a rel="lightbox" href="http://ria-coder.com/temp/wp-content/uploads/2009/05/conditionals.png" class="lightbox-enabled" title="Using Conditionals in MySQL"><img class="size-medium wp-image-281 alignleft" title="conditionals" src="http://ria-coder.com/blog/wp-content/uploads/2009/05/conditionals-300x235.png" alt="conditionals" width="300" height="235"  hspace="10"/></a>Essentially the IF() statement is structured like this:</p>
<p>IF(condition, true code, false code)</p>
<p>However, you can place an IF statement anywhere in a query (from  what i can tell thus far), it gets executed in place and is replaced by  either the <strong>true</strong> code or the <strong>false</strong> code.</p>
<p>Another (much simplified) example:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;TRUE!&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;FALSE!&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>&#8230;and that&#8217;s conditionals with MySQL!</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/using-conditional-statements-with-mysql/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using PHP to Backup and Save your MySQL Database</title>
		<link>http://ria-coder.com/blog/using-php-to-backup-and-save-your-mysql-database</link>
		<comments>http://ria-coder.com/blog/using-php-to-backup-and-save-your-mysql-database#comments</comments>
		<pubDate>Fri, 17 Apr 2009 13:30:35 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[david walsh]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[rick ellis]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=255</guid>
		<description><![CDATA[While working on a recent project, i needed to set up a cron job that would run every X amount of hours and backup a database Here's a class i made to do just that!]]></description>
			<content:encoded><![CDATA[<p>While working on a recent project, i needed to set up a cron job that would run every X amount of hours and backup a database. I&#8217;ve done this a few times before, but only this time (while Googling for a better solution) i found <a title="David Walsh's Blog" href="http://davidwalsh.name/" target="_blank">David Walsh</a>&#8216;s blog post on how to <a href="http://davidwalsh.name/backup-mysql-database-php">Backup Your MySQL Database Using PHP</a>. David&#8217;s done a great job and i definitely recommend you check his blog out in its entireity for some really neat web dev articles.</p>
<p>I decided to go and put David&#8217;s script into class form (my case of OCD is genuine <img src='http://ria-coder.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) and i added one or two things to it. Basically it allows you to backup one or many tables in a database, include or exclude the data from the backup and i also included Rick Ellis&#8217; (of CodeIgniter fame) Zip class to allow you to zip up the backup and stash it somewhere.</p>
<p>Thanks to David Walsh and Rick Ellis!</p>
<p>Here&#8217;s the class: <a href="http://ria-coder.com/blog/wp-content/uploads/2009/04/DatabaseDump.php.txt">DatabaseDump.php</a></p>
<p>&#8230;and here&#8217;s how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dump</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatabaseDump<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;database&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;destination/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dump</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>backup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Be sure to check out the DatabaseDump.php class for the documentation!</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/using-php-to-backup-and-save-your-mysql-database/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

