<?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/tag/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>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 MySQL and JSON</title>
		<link>http://ria-coder.com/blog/using-mysql-and-json</link>
		<comments>http://ria-coder.com/blog/using-mysql-and-json#comments</comments>
		<pubDate>Sat, 25 Apr 2009 14:09:03 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[as3corelib]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=258</guid>
		<description><![CDATA[JSON can be extremely useful when you want to pass data from any platform to any other platform as the format is - essentially - just plain ol' text and computers can parse JSON objects very easily.]]></description>
			<content:encoded><![CDATA[<p><a title="JSON" href="http://json.org/" target="_blank"><strong>JSON</strong></a><strong> </strong>has &#8211; over the past few months &#8211; start working its way more and more into my daily life as a web developer. I find myself using it for all sorts of solutions, whether i&#8217;m using ActionScript or PHP. For those of you who don&#8217;t know, JSON stands for <em>JavaScript Object Notation</em>. JSON is an extremely lightweight, human-readable and highly compacted <strong>data-interchange</strong> format. JSON works on the principle of <em>name/value</em> pairing, and it&#8217;s very easy to read, write and parse.</p>
<p>A typical JSON representation of the following PHP object would be:</p>
<pre>{"title":"Using MySQL and JSON","date":"25 April 2009","timeOfWriting":"15h34"}</pre>

<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;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
      	<span style="color: #000088;">$blogPost</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>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Using MySQL and JSON&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;25 April 2009&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeOfWriting</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;15h34&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>and the following ActionScript object would also be represented as it was above:</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="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> blogPost<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span>title = <span style="color: #990000;">&quot;Using MySQL and JSON&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">date</span> = <span style="color: #990000;">&quot;25 April 2009&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span>timeOfWriting = <span style="color: #990000;">&quot;15h34&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// -----or-----</span>
<span style="color: #009900; font-style: italic;">//var blogPost:Object = {title:&quot;Using MySQL and JSON&quot;, date:&quot;25 April 2009&quot;, timeOfWriting:&quot;15h34&quot;};</span></pre></td></tr></table></div>

<p>JSON can be extremely useful when you want to pass data from any platform to any other platform as the format is &#8211; essentially &#8211; just plain ol&#8217; text and computers can parse JSON objects very easily.</p>
<p>In PHP5, this is supported natively, using the <strong>json_encode</strong> and <strong>json_decode</strong> functions.<br />
However, in ActionScript 3.0, the parsing of JSON strings is not supported in the native ActionScript 3.0 API, so you can either write one yourself or use the <strong>JSONEncoder </strong>or <strong>JSONDecoder</strong> classes found in the <strong><a title="AS3CoreLib" href="http://code.google.com/p/as3corelib/" target="_blank">as3corelib</a></strong><a title="AS3CoreLib" href="http://code.google.com/p/as3corelib/" target="_blank"></a> package.</p>
<p>Here&#8217;s how to encode/decode a JSON string in PHP:</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
</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: #000088;">$blogPost</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>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Using MySQL and JSON&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;25 April 2009&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogPost</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeOfWriting</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;15h34&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// -----or-----</span>
	<span style="color: #666666; font-style: italic;">// $blogPost = array(&quot;title&quot; =&gt; &quot;Using MySQL and JSON&quot;,</span>
	<span style="color: #666666; font-style: italic;">//					&quot;date&quot; =&gt; &quot;25 April 2009&quot;,</span>
	<span style="color: #666666; font-style: italic;">//					&quot;timeOfWriting&quot; =&gt; &quot;15h34&quot;);</span>
&nbsp;
	<span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blogPost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Encoded JSON: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$json</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;Decoded JSON (as associative array):&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</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>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;Decoded JSON (as stdClass object):&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>&#8230;and in ActionScript 3.0 using the <strong>as3corelib</strong> package:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>ObjectUtil<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSONDecoder<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSONEncoder<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> blogPost<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span>title = <span style="color: #990000;">&quot;Using MySQL and JSON&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">date</span> = <span style="color: #990000;">&quot;25 April 2009&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
blogPost<span style="color: #000066; font-weight: bold;">.</span>timeOfWriting = <span style="color: #990000;">&quot;15h34&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// -----or-----</span>
<span style="color: #009900; font-style: italic;">//var blogPost:Object = {title:&quot;Using MySQL and JSON&quot;, date:&quot;25 April 2009&quot;, timeOfWriting:&quot;15h34&quot;};</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> json<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">new</span> JSONEncoder<span style="color: #000000;">&#40;</span>blogPost<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>getString<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Encoded JSON: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> json<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Decoded JSON: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> ObjectUtil<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> JSONDecoder<span style="color: #000000;">&#40;</span>json<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>getValue<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Now that we&#8217;ve gotten that out of the way, let&#8217;s have a look at how we can use JSON inside of MySQL. First off, let me say that i&#8217;m a big fan of structuring one&#8217;s databases correctly and not taking hideous shortcuts like i&#8217;m about to show you, but sometimes doing this hideous shortcut might actually help you develop your appplications faster, and keep things extensible.</p>
<p>I&#8217;ve found that i often have to keep changing my database structure when clients have changes of heart (and man, do they change them often!). It becomes extremely frustrating to have to restructure an entire database (and all associated PHP/AS3 code) every time a client remembers that he forgot about needing to store something as ridiculous the big-toe girdths of his future website&#8217;s users.</p>
<p>Now, i&#8217;m certainly not a patient person, and &#8211; to be honest &#8211; i don&#8217;t have time to fuck about and keep changes logic just to accomodate menial extra pieces of info. What i do therefore is usually keep a <em>settings</em> column in the <em>users</em> table, set it&#8217;s type to <strong>Text</strong> and store JSON strings in there to keep track of all the silly idiosyncratic (and sometimes idiotic) requirements of the client. Then all i have to do is parse out that string and apply some business logic to the values i find in that row under the <em>settings</em> column.</p>
<p>I find that it makes things a lot simpler and with orders of magnitude less ballaches.</p>
<p>What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/using-mysql-and-json/feed</wfw:commentRss>
		<slash:comments>6</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>
		<item>
		<title>Working with LAMPP on Linux Mint</title>
		<link>http://ria-coder.com/blog/working-with-lampp-on-linux-mint</link>
		<comments>http://ria-coder.com/blog/working-with-lampp-on-linux-mint#comments</comments>
		<pubDate>Mon, 26 Jan 2009 20:07:28 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[lampp]]></category>
		<category><![CDATA[linux mint]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=116</guid>
		<description><![CDATA[Following from my previous post, i decided to try and mimick my development environment at work on my laptop. The quickest and easiest way to do this is to install XAMPP for Linux. The folks over at apachefriends have given us one of the greatest gifts a web-developer geek could want&#8230; A pre-configured, fully open]]></description>
			<content:encoded><![CDATA[<p>Following from my previous post, i decided to try and mimick my development environment at work on my laptop. The quickest and easiest way to do this is to install <a title="XAMPP for Linux" href="http://www.apachefriends.org/en/xampp-linux.html" target="_blank">XAMPP for Linux</a>. The folks over at <strong>apachefriends</strong> have given us one of the greatest gifts a web-developer geek could want&#8230; A pre-configured, fully open and customizable, versatile setup of <strong>LAMPP</strong> (<strong>L</strong>inux, <strong>A</strong>pache, <strong>M</strong>ySQL, <strong>P</strong>HP and <strong>P</strong>erl). Here&#8217;s what the package includes:</p>
<blockquote><p>Apache 2.2.11, MySQL 5.1.30, PHP 5.2.8 &amp; PEAR + SQLite 2.8.17/3.3.17 + multibyte (mbstring) support, Perl 5.10.0, ProFTPD 1.3.1, phpMyAdmin 3.1.1, OpenSSL 0.9.8i, GD 2.0.1, Freetype2 2.1.7, libjpeg 6b, libpng 1.2.12, gdbm 1.8.0, zlib 1.2.3, expat 1.2, Sablotron 1.0, libxml 2.7.2, Ming 0.3, Webalizer 2.01, pdf class 009e, ncurses 5.3, mod_perl 2.0.4, FreeTDS 0.63, gettext 0.11.5, IMAP C-Client 2004e, OpenLDAP (client) 2.3.11, mcrypt 2.5.7, mhash 0.8.18, eAccelerator 0.9.5.3, cURL 7.19.2, libxslt 1.1.8, phpSQLiteAdmin 0.2, libapreq 2.08, FPDF 1.6, XAMPP Control Panel 0.6, bzip 1.0.5, PBXT 1.0.07-rc</p></blockquote>
<p>Now stick that in your pipe and serve it!</p>
<p>This package must <strong>NOT</strong> be used on production server. <strong>NEVER!</strong> Please view <a title="LAMPP security" href="http://www.apachefriends.org/en/xampp-linux.html#381" target="_blank">this</a> page for information about LAMPP&#8217;s inherent security flaws and why it benefits you on a local machine, but not on a production server.</p>
<p>The LAMPP package is simple enough to install, but there is one thing i noticed that is a bit of a ball-ache&#8230; By default, you cannot use LAMPP without an active internet connection. However, there is a quick fix:</p>
<ol>
<li>Open the httpd.conf file (<em>sudo nano /path/to/</em>httpd.conf)</li>
<li>Look for the line that says <strong>Listen 80</strong></li>
<li>Change the line to <strong>Listen 127.0.0.1:80</strong></li>
<li>Save the file and restart apache</li>
<li>Run <a href="http://localhost" target="_blank">http://localhost</a></li>
<li>It works! <img src='http://ria-coder.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/working-with-lampp-on-linux-mint/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

