<?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>code-diesel &#187; data</title>
	<atom:link href="http://www.codediesel.com/tag/data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Splitting large MySQL dump files</title>
		<link>http://www.codediesel.com/php/splitting-large-mysql-dump-files/</link>
		<comments>http://www.codediesel.com/php/splitting-large-mysql-dump-files/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 11:48:09 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[data]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2922</guid>
		<description><![CDATA[One of the frustrating things with working with MySQL is of importing large sql dump files. Either you get a &#8216;max execution time exceeded&#8217; error from PHP or a &#8216;Max_allowed_packet_size&#8217; from MySQL. In a recent task I needed to import a table of around a million records on a remote host, which quickly became an [...]]]></description>
			<content:encoded><![CDATA[<p>One of the frustrating things with working with MySQL is of importing large sql dump files. Either you get a &#8216;max execution time exceeded&#8217; error from PHP or a &#8216;Max_allowed_packet_size&#8217; from MySQL. In a recent task I needed to import a table of around a million records on a remote host, which quickly became an exercise in frustration due to various limitations on the server. SSH was of no help as changing the configuration files was restricted to the root user.</p>
<p>My last resort was to split the huge &#8216;INSERT&#8217; statements into smaller size files. Manually doing the same is obviously time consuming and error prone; the only other solution is to write a small script to split the insert statements. This was to be a quick hack so the parsing code was to be of minimum complexity. Splitting a sql dump containing extended insert statements is somewhat complex so you need to have the dump file in a simple format &#8211; each insert statement should be on its own line as shown below.<br />
<span id="more-2922"></span></p>

<div class="wp_codebox"><table><tr id="p29225"><td class="code" id="p2922code5"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`dt<span style="color: #008080; font-weight: bold;">_</span>codes`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> ...
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`dt<span style="color: #008080; font-weight: bold;">_</span>codes`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> ...
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`dt<span style="color: #008080; font-weight: bold;">_</span>codes`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> ...
.
.</pre></td></tr></table></div>

<p>You can create the initial dump file in a simple format using the following command or you can do it using phpMyAdmin.</p>

<div class="wp_codebox"><table><tr id="p29226"><td class="code" id="p2922code6"><pre class="mysql" style="font-family:monospace;">mysqldump <span style="color: #CC0099;">-</span>uUSER <span style="color: #CC0099;">-</span>pPASS <span style="color: #CC0099;">--</span><span style="color: #990099; font-weight: bold;">databases</span> DATABASE_NAME <span style="color: #CC0099;">--</span><span style="color: #990099; font-weight: bold;">tables</span> TABLE_NAME \
<span style="color: #CC0099;">--</span>extended<span style="color: #CC0099;">-</span><span style="color: #990099; font-weight: bold;">insert</span> <span style="color: #CC0099;">=</span> <span style="color: #9900FF; font-weight: bold;">FALSE</span> <span style="color: #CC0099;">&gt;</span> dump.sql</pre></td></tr></table></div>

<p>Once you have the big dump file you can use the following PHP script for splitting the file into smaller chunks. Change the variable &#8216;$max_lines_per_split&#8217; to whatever value you think will work on your system.</p>

<div class="wp_codebox"><table><tr id="p29227"><td class="code" id="p2922code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/* Number of 'insert' statements per file */</span>
<span style="color: #000088;">$max_lines_per_split</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50000</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$dump_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dump.sql&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$split_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dump-split-<span style="color: #009933; font-weight: bold;">%d</span>.sql&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dump_directory</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;./sql-dump/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$line_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total_lines</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump_file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/* Only read 'insert' statements */</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/insert/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$line_count</span><span style="color: #339933;">++;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* Copy buffer to the split file */</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$line_count</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$max_lines_per_split</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dump_directory</span> <span style="color: #339933;">.</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$split_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file_count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$out_write</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$out_write</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$out_write</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$line_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$file_count</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009933; font-style: italic;">/* Write out the remaining buffer */</span>
        <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dump_directory</span> <span style="color: #339933;">.</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$split_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file_count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$out_write</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w+&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$out_write</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$out_write</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;done.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once the dump file has been split into smaller ones, you can gzip them to reduce the size further.</p>

<div class="wp_codebox"><table><tr id="p29228"><td class="code" id="p2922code8"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> dump-split-<span style="color: #000000; font-weight: bold;">*</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/splitting-large-mysql-dump-files/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>International Airport codes download</title>
		<link>http://www.codediesel.com/data/international-airport-codes-download/</link>
		<comments>http://www.codediesel.com/data/international-airport-codes-download/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 11:11:57 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/php/international-airport-codes/</guid>
		<description><![CDATA[During a recent project I needed a database of IATA airport codes. Airports around the world are universally known by a unique three-letter code: the &#8220;International Air Transport Association (IATA) Location Identifier&#8221;. It is much easier for pilots, travel agents, frequent flyers, baggage handlers and anyone having anything to do with airlines to say and [...]]]></description>
			<content:encoded><![CDATA[<p>During a recent project I needed a database of IATA airport codes. Airports around the world are universally known by a unique three-letter code: the &#8220;International Air Transport Association (IATA) Location Identifier&#8221;. It is much easier for pilots, travel agents, frequent flyers, baggage handlers and anyone having anything to do with airlines to say and write <em>LGA</em> then the full &#8220;<em>New York, NY &#8211; La Guardia Airport</em>&#8220;.<br />
<span id="more-2850"></span><br />
A sample is shown below.</p>

<div class="wp_codebox"><table><tr id="p285010"><td class="code" id="p2850code10"><pre class="text" style="font-family:monospace;">Airport			Code
Aalborg, Denmark 	AAL
Aalesund, Norway	AES
Aasiaat, Greenland 	JEG
Abadan, Iran 		ABD
Abakan, Russia		ABA
.
.</pre></td></tr></table></div>

<p>After scouting around for a while I stumbled upon a HTML list at <a target="_blank" href="http://www.orbitz.com/App/global/airportCodes.jsp">orbitz</a>. To make it usable in PHP I further converted the data to various formats (CSV, SQL, XML) for ease of use. The complete list of files is available below for download. The files contain codes for 3592 international airports sorted by name. This can be useful if your web application needs to convert airport names to their respective IATA codes.</p>
<div  class="download2">
<a href="http://www.codediesel.com/downloads/airport-codes">Download IATA Airport Codes (sql, csv, xml)</a><br />
<span>Downloads : 601  / File size : 120 kB</span>
</div>
<p>Further Reading:<br />
<a target="_blank" href="http://www.skygod.com/asstd/abc.html">Airport ABCs: An Explanation of Airport Identifier Codes</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/international-airport-codes-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating random data on the client side</title>
		<link>http://www.codediesel.com/data/generating-random-data-on-the-client-side/</link>
		<comments>http://www.codediesel.com/data/generating-random-data-on-the-client-side/#comments</comments>
		<pubDate>Fri, 21 May 2010 10:07:31 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2658</guid>
		<description><![CDATA[Automatically creating fake or sample data is a frequent requirement for front-end web developers. Although usually not tedious, there are times when you need to quickly and automatically generate structured data for your html forms or CMS systems for testing purposes. Faker.js is a JavaScript implementation inspired by Benjamin Curtis&#8217;s Ruby Gem Faker and Perl&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Automatically creating fake or sample data is a frequent requirement for front-end web developers. Although usually not tedious, there are times when you need to quickly and automatically generate structured data for your html forms or CMS systems for testing purposes.</p>
<p><a target="_blank" href="http://github.com/Marak/Faker.js">Faker.js</a> is a JavaScript implementation inspired by Benjamin Curtis&#8217;s Ruby Gem <a href="http://faker.rubyforge.org/">Faker</a> and Perl&#8217;s <a href="http://search.cpan.org/~jasonk/Data-Faker-0.07/lib/Data/Faker.pm">Data::Faker</a> that lets you generate commonly required data quickly. You can check the <a href="http://maraksquires.com/Faker.js/">demo page</a> to get an idea.<br />
<span id="more-2658"></span></p>
<h4>Getting Fake.js</h4>
<p>You can download the library form <a href="http://github.com/Marak/Faker.js">github</a> and include in your pages where you need to generate the data.</p>

<div class="wp_codebox"><table><tr id="p265819"><td class="code" id="p2658code19"><pre class="javascript" style="font-family:monospace;">..
<span style="color: #339933;">&lt;</span>script src <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Faker/Faker.js&quot;</span> type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
..</pre></td></tr></table></div>

<h4>Generating fake data</h4>
<p>The API is divided into various sections as show below:</p>

<div class="wp_codebox"><table><tr id="p265820"><td class="code" id="p2658code20"><pre class="text" style="font-family:monospace;"># Name
    * findName
# Address
    * zipCode
    * city
    * streetName
    * streetAddress
    * secondaryAddress
    * ukCounty
    * ukCountry
# PhoneNumber
    * phoneNumber
# Internet
    * email
    * userName
    * domainName
    * domainWord
...</pre></td></tr></table></div>

<p>So if you need to generate a random email address or a zip code you could do it like this:</p>

<div class="wp_codebox"><table><tr id="p265821"><td class="code" id="p2658code21"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> randomEmail <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Internet</span>.<span style="color: #660066;">email</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> randomZip <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Address</span>.<span style="color: #660066;">zipCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Some sample API methods are shown below, but there are more of them which you can find <a target="_blank" href="http://github.com/Marak/Faker.js">here</a> in the API section.</p>

<div class="wp_codebox"><table><tr id="p265822"><td class="code" id="p2658code22"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> longParagraph <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Lorem</span>.<span style="color: #660066;">paragraphs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> singleSentence <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Lorem</span>.<span style="color: #660066;">sentence</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> companyName<span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Company</span>.<span style="color: #660066;">companyName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> catchPhrase <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Company</span>.<span style="color: #660066;">catchPhrase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>One of the interesting methods is &#8216; Faker.Company.catchPhrase()&#8217;, which generates catchy technological phrases. A kind of a tag line generator for your new multi-million dollar company <img src='http://www.codediesel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . A sample output is shown below.</p>

<div class="wp_codebox"><table><tr id="p265823"><td class="code" id="p2658code23"><pre class="text" style="font-family:monospace;">Stand-alone 5th generation utilisation
Ergonomic explicit focus group
Horizontal human-resource solution
Automated contextually-based knowledge base
Distributed multi-state encoding
Extended zero administration interface
Proactive coherent productivity
Streamlined national approach
Total transitional algorithm
Stand-alone fault-tolerant moderator</pre></td></tr></table></div>

<p>The API also includes several helper methods that lets you create bulk fake data using the single API methods. For example you can generate complete user information templates cards by using a single helper method <span class="method">&#8216;Faker.Helpers.userCard()&#8217;</span>. A sample run is shown below:</p>

<div class="wp_codebox"><table><tr id="p265824"><td class="code" id="p2658code24"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066;">name</span><span style="color: #339933;">:</span> Blair Nikolaus
username<span style="color: #339933;">:</span> Fernando_Olson
email<span style="color: #339933;">:</span> Jacklyn_Brekke<span style="color: #339933;">@</span>aurore.<span style="color: #000066;">name</span>
address<span style="color: #339933;">:</span>street<span style="color: #339933;">:</span> Kozey Meadow
suite<span style="color: #339933;">:</span> Apt. <span style="color: #CC0000;">664</span>
city<span style="color: #339933;">:</span> Felipastad
zipcode<span style="color: #339933;">:</span> <span style="color: #CC0000;">88071</span>
&nbsp;
phone<span style="color: #339933;">:</span> 571.540.8605 x136
website<span style="color: #339933;">:</span> reba.<span style="color: #660066;">co</span>.<span style="color: #660066;">uk</span>
company<span style="color: #339933;">:</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> Kuhic and Sons
catchPhrase<span style="color: #339933;">:</span> Integrated solution<span style="color: #339933;">-</span>oriented Graphical User Interface
bs<span style="color: #339933;">:</span> seize scalable web services</pre></td></tr></table></div>

<p>The &#8216;Faker.Helpers.userCard()&#8217; method returns a nested object, so you will need to recursively traverse the object to extract the data. A simple function to do the same is given below:</p>

<div class="wp_codebox"><table><tr id="p265825"><td class="code" id="p2658code25"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// Recursively traverse a nested Javascript object and return it.</span>
<span style="color: #003366; font-weight: bold;">function</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> prop<span style="color: #339933;">,</span> res <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>prop <span style="color: #000066; font-weight: bold;">in</span> obj<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        res <span style="color: #339933;">+=</span> prop <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
        res <span style="color: #339933;">+=</span> prop <span style="color: #339933;">+</span> <span style="color: #3366CC;">': '</span> <span style="color: #339933;">+</span> obj<span style="color: #009900;">&#91;</span>prop<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">return</span> res<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>So now you can do something like this:</p>

<div class="wp_codebox"><table><tr id="p265826"><td class="code" id="p2658code26"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> Faker.<span style="color: #660066;">Helpers</span>.<span style="color: #660066;">userCard</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> printObj<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...</pre></td></tr></table></div>

<h4>Another Randomizer library</h4>
<p><a target="_blank" href="http://code.google.com/p/clubajax/source/browse/">Club AJAX Mock Data Randomizer</a> library is another library that lets you generate random data quickly. This library lets you generate random dates, colors, boolean values which is lacking in the Faker library. Check a simple <a href="http://www.codediesel.com/data/scripts/random/index.html">demo</a> using this library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/generating-random-data-on-the-client-side/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test data generation for MySQL</title>
		<link>http://www.codediesel.com/data/test-data-generation-for-mysql/</link>
		<comments>http://www.codediesel.com/data/test-data-generation-for-mysql/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 09:28:16 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1833</guid>
		<description><![CDATA[generating test data for mysql]]></description>
			<content:encoded><![CDATA[<p>One of the most time consuming steps in developing a database based application is test data generation. Imagine you have created a shopping cart application for your client, containing dozens of tables and hundreds of fields. Everything is ready for testing, but the problem is your database is empty. You at least require a modicum of test data in the database to proceed with the testing. You can choose to manually enter a small set of random data into the database, but you lose a couple of precious days in the process. What you require is a data generator that automatically generates test data for your database.<br />
<span id="more-1833"></span><br />
There are a couple of data generators available for free on the web, but they are only suitable if your database schema is small, with no more than three to four tables and total number of fields not exceeding  a dozen or so.  While browsing I came across <a target="_blank" href="http://www.upscene.com/products.adg.index.php">Advanced Data Generator (ADG)</a>, a test data generator for MySQL. ADG allows you to generate a random test data for dates, URLS, E-mail addresses, cities, names, countries and more. </p>
<h4>Data Generation</h4>
<p>Once you connect ADG to your MySQL server and register a database, you are ready to go. Generating the test data is quite simple. First you create a project for your data generation work. Once done, you select the table and fields you want to generate data for, select the type of test data to generate – dates, urls, names etc. Set the total number of records to generate and then run the project. This will create the test data for your database project. The test data can be saved directly to the connected database or you can save it as a separate SQL script, YAML or CSV file.  Below is a sample screenshot of a data generation project.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg1-300x267.gif" alt="adg1" title="adg1" width="300" height="267" class="aligncenter size-medium wp-image-1832" /></a></p>
<p>The Advanced Data Generator comes with a very useful repository of real-life like data, in order to generate meaningful test-data for the database. You can also use custom SQL scripts or Macros to generate custom string data.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/11/adg2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/11/adg2-295x300.gif" alt="adg2" title="adg2" width="295" height="300" class="aligncenter size-medium wp-image-1838" /></a></p>
<h4>In closing</h4>
<p>Although not free, its a small price to pay for the excellent automation it provides during database creation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/test-data-generation-for-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Number to text conversion</title>
		<link>http://www.codediesel.com/data/number-to-text-conversion/</link>
		<comments>http://www.codediesel.com/data/number-to-text-conversion/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 14:50:49 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=780</guid>
		<description><![CDATA[phpguru.org offers a small and useful class to convert numbers to their textual equivalent. If you are building a accounting or invoicing application it may come in handy. The class can be downloaded form here. A sample code using the class is shown below. &#60;?php &#160; require_once 'libs/numtotext.php'; &#160; &#160; $tt = new TextualNumber&#40;&#41;; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.phpguru.org/">phpguru.org</a> offers a small and useful class to convert numbers to their textual equivalent. If you are building a accounting or invoicing application it may come in handy. The class can be downloaded form <a target="_blank" href="http://www.phpguru.org/downloads/TextualNumber/">here</a>. A sample code using the class is shown below.<br />
<span id="more-780"></span></p>

<div class="wp_codebox"><table><tr id="p78029"><td class="code" id="p780code29"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'libs/numtotext.php'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000088;">$tt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextualNumber<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/* Catch 'out of range' and 'invalid character' exceptions */</span>
    try <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$tt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;197533408989&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</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: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>The above code prints:</p>

<div class="wp_codebox"><table><tr id="p78030"><td class="code" id="p780code30"><pre class="dos" style="font-family:monospace;">one hundred and ninety-seven billion 
five hundred and thirty-three million 
four hundred and eight thousand 
nine hundred and eighty-nine</pre></td></tr></table></div>

<p>The class supports a range up to 999999999999999999 and also supports decimal numbers.<br />
One thing to note is that The billion/trillion etc suffixes are done using the American style (eg 9 zeros for billion, 12 for trillion).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/number-to-text-conversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Free Geolocation API tool</title>
		<link>http://www.codediesel.com/tools/free-geolocation-api-tool/</link>
		<comments>http://www.codediesel.com/tools/free-geolocation-api-tool/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 04:33:15 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[data]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=682</guid>
		<description><![CDATA[NOTE: http://www.ip2location.com have done away with the free api access from their site. So the following sample code will no longer work. They now provide a free sample database on their site and also a complete paid version. iplocationtools.com offers a free geolocation API that lets you query with an ip address and get the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: http://www.ip2location.com have done away with the free api access from their site. So the following sample code will no longer work. They now provide a free sample database on their site and also a complete paid version.</strong><br />
<br />
<del datetime="2009-07-15T16:28:16+00:00"><a target="_blank" href="http://iplocationtools.com/">iplocationtools.com</a>  offers a free geolocation API that lets you query with an ip address and get the location details such as city, country, zip, latitude, longitude etc. The site also offers a free MySQL database for the same if you would like to install it on your server. I&#8217;ve used CURL to wrap the API access. The complete function with a sample query and the response is shown below.</del><br />
<span id="more-682"></span></p>

<div class="wp_codebox"><table><tr id="p68238"><td class="code" id="p682code38"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
   <span style="color: #009933; font-style: italic;">/**
    * Geolocation API access
    *
    * @param    string  $ip         IP address to query
    * @param    string  $format     output format of response
    *
    * @return   string  XML, JSON or CSV string
    */</span>
    <span style="color: #000000; font-weight: bold;">function</span> get_ip_location<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$format</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* Set allowed output formats */</span>
        <span style="color: #000088;">$formats_allowed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;raw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* IP location query url */</span>
        <span style="color: #000088;">$query_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://iplocationtools.com/ip_query.php?ip=&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* Male sure that the format is one of json, xml, raw.
           Or else default to xml */</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$formats_allowed</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$format</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$query_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ip}</span>&amp;output=<span style="color: #006699; font-weight: bold;">{$format}</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* Init CURL and its options*/</span>
        <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$query_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009933; font-style: italic;">/* Execute CURL and get the response */</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000088;">$location_data</span> <span style="color: #339933;">=</span> get_ip_location<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;209.85.153.104&quot;</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;">$location_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Query response:</p>

<div class="wp_codebox"><table><tr id="p68239"><td class="code" id="p682code39"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Response<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>209.85.153.104<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Ip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CountryCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>US<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CountryCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CountryName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>United States<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CountryName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RegionCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>06<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RegionCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RegionName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>California<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RegionName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;City<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mountain View<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/City<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ZipPostalCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>94043<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ZipPostalCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Latitude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>37.4192<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Latitude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Longitude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-122.057<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Longitude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Response<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The function by default returns a XML response, but you can also get a response in json or csv format, as shown below.</p>

<div class="wp_codebox"><table><tr id="p68240"><td class="code" id="p682code40"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* Get response in 'json' format' */</span>
<span style="color: #000088;">$location_data</span> <span style="color: #339933;">=</span> get_ip_location<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;209.85.153.104&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p68241"><td class="code" id="p682code41"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;Ip&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;209.85.153.104&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;Status&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;OK&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;CountryCode&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;US&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;CountryName&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;United States&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;RegionCode&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;06&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;RegionName&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;California&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;City&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Mountain View&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;ZipPostalCode&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;94043&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;Latitude&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;37.4192&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;Longitude&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;-122.057&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>or</p>

<div class="wp_codebox"><table><tr id="p68242"><td class="code" id="p682code42"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/* Get response in 'csv' format' */</span>
<span style="color: #000088;">$location_data</span> <span style="color: #339933;">=</span> get_ip_location<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;209.85.153.104&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;raw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p68243"><td class="code" id="p682code43"><pre class="csv" style="font-family:monospace;">209.85.153.104,OK,US,United States,06,California,
Mountain View,94043,37.4192,-122.057</pre></td></tr></table></div>

<p>You can further parse the returned XML using SimpleXML.</p>

<div class="wp_codebox"><table><tr id="p68244"><td class="code" id="p682code44"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #000088;">$location_data</span> <span style="color: #339933;">=</span> get_ip_location<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;209.85.153.104&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
    try <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #0000ff;">&quot;Error parsing XML.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #000000; font-weight: bold;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/free-geolocation-api-tool/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Generating test data for MySQL</title>
		<link>http://www.codediesel.com/mysql/generating-test-data-for-mysql/</link>
		<comments>http://www.codediesel.com/mysql/generating-test-data-for-mysql/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 04:34:08 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=572</guid>
		<description><![CDATA[The most common type of web application a developer encounters are database related. But rarely is the case when you have the required data in your database during testing, making it a frequent source of frustration for programmers, who than have to manually populate the database. Having a dummy set of data is always a [...]]]></description>
			<content:encoded><![CDATA[<p>The most common type of web application a developer encounters are database related. But rarely is the case when you have the required data in your database during testing, making it a frequent source of frustration for programmers, who than have to manually populate the database. Having a dummy set of data is always a good thing.</p>
<p><span id="more-572"></span></p>
<p><a title="dummy data generator" href="http://www.generatedata.com/#generator" target="_blank">generatedata.com</a> is one such tool. Generatedata lets you specify the database schema details and generates the dummy sql data for you, with table creation and complete inserts. The data can further be exported to html, excel, xml or csv formats. The tool is available online and there is also a downloadable version of the tool if you like to modify the code or need to install it on your server or development machine.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/03/testdata.gif"><img class="aligncenter size-medium wp-image-576" title="testdata" src="http://www.codediesel.com/wp-content/uploads/2009/03/testdata-300x168.gif" alt="testdata" width="300" height="168" /></a></p>
<p>The tool also has an option to generate country specific data; currently limited to Canada,Netherlands,UK and the US. If you need to add other countries to the list, you have the option of modifying the code to suit your specific purpose. Even though there are many free tools available online with the same purpose, I find Generatedata to be simple to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/mysql/generating-test-data-for-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

