<?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>Kavoir &#187; Programming Tips &amp; Insights</title>
	<atom:link href="http://www.kavoir.com/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kavoir.com</link>
	<description>Just another dumbass webmaster, goofing around...</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:59:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL: LOAD DATA LOCAL INFILE only imports 1 or 2 rows?</title>
		<link>http://www.kavoir.com/2012/02/mysql-load-data-local-infile-only-imports-1-or-2-rows.html</link>
		<comments>http://www.kavoir.com/2012/02/mysql-load-data-local-infile-only-imports-1-or-2-rows.html#comments</comments>
		<pubDate>Tue, 07 Feb 2012 01:23:04 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[SQL / MySQL Tips and Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/?p=2739</guid>
		<description><![CDATA[It is common to import CSV files into MySQL database. You can do this with phpMyAdmin with small CSV files but with large ones, you would probably encounter the memory error and had to switch to MySQL command line “LOAD DATA LOCAL INFILE” to do the job. It looks like something like this: LOAD DATA [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>It is common to import CSV files into MySQL database. You can do this with phpMyAdmin with small CSV files but with large ones, you would probably encounter the memory error and had to switch to MySQL command line “LOAD DATA LOCAL INFILE” to do the job.</p>

<p>It looks like something like this:</p>
<pre><code>LOAD DATA LOCAL INFILE 'your.csv'
INTO TABLE `your_table`
FIELDS TERMINATED BY ','
ENCLOSED BY '&quot;'
LINES TERMINATED BY '\n'
(field1, field2, field3)</code></pre>
<p>And then you encounter another problem that it only imports the first 1 or 2 rows and then it stops. After some researching and trying, I was sure it’s something to do with the “<strong>LINES TERMINATED BY</strong>” directive. Depending on the platform that the CSV file is created on, the line delimiter may be</p>
<ol>
<li><strong>\n</strong> </li>
<li><strong>\r\n</strong> </li>
<li><strong>\r</strong> </li>
</ol>
<p>And you need to be correct on the line delimiter to properly parse the CSV file. </p>
<p>So the solution is to <strong>try them all</strong> one by one and see which one of them works. Chances are, one of them would make the whole command successfully import ALL rows.</p>
<p>Another simple approach is to deprive the whole command of the “<strong>LINES TERMINATED BY</strong>” directive and let MySQL do the call. It’ll probably detect things right but in my case, this doesn’t work but specifying ‘\r’.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2010/11/mysql-export-table-to-csv-text-files-for-excel.html" rel="bookmark" title="November 18, 2010">MySQL: Export Table to CSV Text Files for Excel</a></li>
<li><a href="http://www.kavoir.com/2010/10/mysql-log-files-are-taking-a-lot-of-disk-space-how-to-disable-and-delete-them.html" rel="bookmark" title="October 25, 2010">MySQL log files are taking a lot of disk space &ndash; How to disable and delete them?</a></li>
<li><a href="http://www.kavoir.com/2009/03/sql-randomly-shuffle-rows-or-records-reorder-them-in-a-random-order.html" rel="bookmark" title="March 23, 2009">SQL: Randomly Shuffle Rows or Records &ndash; Reorder them in a random order</a></li>
<li><a href="http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html" rel="bookmark" title="February 17, 2011">MySQL: How to export a database / table to XML?</a></li>
<li><a href="http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html" rel="bookmark" title="May 17, 2009">MySQL: Update Multiple Rows or Records with One Single Query</a></li>
</ul>
<p><!-- Similar Posts took 2.384 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2012/02/mysql-load-data-local-infile-only-imports-1-or-2-rows.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Check if A String Contain Only Uppercase / Capital Letters</title>
		<link>http://www.kavoir.com/2012/01/php-check-if-a-string-contain-only-uppercase-capital-letters.html</link>
		<comments>http://www.kavoir.com/2012/01/php-check-if-a-string-contain-only-uppercase-capital-letters.html#comments</comments>
		<pubDate>Fri, 20 Jan 2012 06:32:44 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/?p=2663</guid>
		<description><![CDATA[Sometimes you would want to check if a string is an acronym or an abbreviation by testing if it only contains capitalized letters from A to Z and nothing else. There are 2 ways to accomplish this simple task in PHP. ctype_upper() Use the native ctype_upper() function and you will know if the provided string [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Sometimes you would want to check if a string is an acronym or an abbreviation by testing if it only contains capitalized letters from <strong>A to Z</strong> and nothing else. There are 2 ways to accomplish this simple task in PHP.</p>

<h2>ctype_upper()</h2>
<p>Use the native <a href="http://php.net/manual/en/function.ctype-upper.php">ctype_upper</a>() function and you will know if the provided string contains only uppercase letters:</p>
<pre><code>if (<strong>ctype_upper</strong>($string)) {
	echo $string.' is all uppercase letters.';
} else {
	echo $string.' is not all uppercase letters.';
}</code></pre>
<p>The <a href="http://www.php.net/manual/en/ref.ctype.php">Ctype functions</a> would turn out to be very handy when you want to test a string against different character types – digits, alphabetic, alpha-numeric, lowercase letters, uppercase letter, and even punctuations, etc. See the full list here: <a href="http://www.php.net/manual/en/ref.ctype.php">http://www.php.net/manual/en/ref.ctype.php</a></p>
<h2>strtoupper()</h2>
<p>Use the <strong>strtoupper</strong>() function to transform the string into all uppercase characters that’s capitalized letters, and then compare the transformed string against the original one to see if they are identical. If they are, then you are pretty sure the original string was also a string consisting of ONLY capital letters.</p>
<pre><code>if (<strong>strtoupper($string) == $string</strong>) {
	echo $string.' is all uppercase letters.';
}</code></pre>
<h2>Check if A String Consists of Only Lowercase Letters</h2>
<p>The same goes true if you want to do the test other way around. Just use <strong>ctype_lower</strong>() and <strong>strtolower</strong>() instead.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/04/php-string-case-uppercase-all-letters-or-lowercase-all-letters-in-a-string-uppercase-first-letter-of-a-string-uppercase-first-letter-of-all-words-in-a-string.html" rel="bookmark" title="April 23, 2009">PHP String Case: Uppercase all Letters or Lowercase all Letters in a String | Uppercase First Letter of a String | Uppercase First Letter of all Words in a String</a></li>
<li><a href="http://www.kavoir.com/2011/04/php-class-converting-plural-to-singular-or-vice-versa-in-english.html" rel="bookmark" title="April 3, 2011">PHP Class: Convert Plural to Singular or Vice Versa in English</a></li>
<li><a href="http://www.kavoir.com/2010/09/php-checking-text-strings-against-reserved-or-censored-words.html" rel="bookmark" title="September 27, 2010">PHP: Checking Text Strings against Reserved or Censored Words</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-change-array-key-case-all-array-keys-to-lowercase-or-uppercase.html" rel="bookmark" title="June 2, 2009">PHP: Change Array Key Case &#8211; All Array Keys to Lowercase or Uppercase</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-create-an-array-of-a-range-of-characters-numbers-or-letters-or-multiple-identical-values.html" rel="bookmark" title="June 2, 2009">PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values</a></li>
</ul>
<p><!-- Similar Posts took 2.401 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2012/01/php-check-if-a-string-contain-only-uppercase-capital-letters.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FFVCL &#8211; FFmpeg Delphi VCL for Video / Audio Apps Development</title>
		<link>http://www.kavoir.com/2012/01/ffmpeg-delphi-vcl-for-video-audio-applications-development.html</link>
		<comments>http://www.kavoir.com/2012/01/ffmpeg-delphi-vcl-for-video-audio-applications-development.html#comments</comments>
		<pubDate>Fri, 13 Jan 2012 13:50:39 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[Desktop Development]]></category>
		<category><![CDATA[Internet Tools]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/?p=2613</guid>
		<description><![CDATA[This post is dedicated to one of my friends, Coolie (not his real name but he preferred to be called that way among friends), a father and self-entrepreneur who created the outstanding Delphi VCL component for FFmpeg that makes it extremely easy to develop audio and video applications for Windows. For those who are not [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.delphiffmpeg.com/"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border: 0px;" title="ffmpeg delphi vcl" src="http://www.kavoir.com/wp-content/uploads/2012/01/ffmpeg-delphi-vcl.jpg" alt="ffmpeg delphi vcl" width="239" height="164" align="right" border="0" /></a>This post is dedicated to one of my friends, Coolie (not his real name but he preferred to be called that way among friends), a father and self-entrepreneur who created the outstanding <a href="http://www.delphiffmpeg.com/">Delphi VCL component for FFmpeg</a> that makes it extremely easy to develop audio and video applications for Windows.</p>

<p>For those who are not Windows desktop developers, <a href="http://ffmpeg.org/">FFmpeg</a> is the ONE video and audio applications library across all major platforms that is able to encode, decode, edit, convert and stream audio and video. It is widely adopted as the standard library for multi-media applications development. Chances are, what you currently have for media player in your operating system uses FFmpeg to do all the underlying work.</p>
<p>The problem with FFmpeg is that it’s only got a command line interface. You would definitely find it fascinating if you are a Linux guru, but not GUI users. Developers must create another layer of interface to accommodate end users, another layer of abstraction for FFmpeg, and that’s exactly where Coolie’s talent comes in, who heroically produced the <a href="http://www.delphiffmpeg.com/">Delphi VCL for FFmpeg</a> and the <a href="http://www.activexffmpeg.com/">ActiveX OCX Controls for FFmpeg</a>. Problem solved for people who want to make video and audio applications in Windows but daunted by the command-line FFmpeg.</p>
<p>Simply ground-breaking work he has made, Coolie graduated from <a href="http://www.tsinghua.edu/">Tsinghua</a> university, the China counterpart of <a href="http://www.mit.edu/">MIT</a> or <a href="http://www.princeton.edu">Princeton</a> – approximately 100,000 high school students each year compete for just 1 admission to Tsinghua. Think about that.</p>
<p>Feel free to bug him if you are interested in developing a multi-media application yourself – it’s not so hard as it may seem because many contemporary languages and platforms are made to be used by absolute programming beginners, such as <a href="http://en.wikipedia.org/wiki/Visual_Basic_.NET">VB.NET</a>.<br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2007/05/beginning-silverlight-and-xaml-quickstarts-resources.html" rel="bookmark" title="May 5, 2007">Beginning Silverlight, and XAML Resources &#8211; QuickStarts, Videos, Walkthroughs</a></li>
<li><a href="http://www.kavoir.com/2009/08/new-tags-of-html-5-a-new-features-tutorial.html" rel="bookmark" title="August 27, 2009">New Tags of HTML 5 (A New Features Tutorial)</a></li>
<li><a href="http://www.kavoir.com/2009/06/best-javascript-books-for-learning-javascript-programming-and-development.html" rel="bookmark" title="June 17, 2009">Best JavaScript Books for Learning JavaScript Programming and Development</a></li>
<li><a href="http://www.kavoir.com/2007/12/encyclopedia-of-dreamhost-coupon-codes.html" rel="bookmark" title="December 1, 2007">DreamHost Promo Codes, Coupons and Discount Codes for Cheap Web Hosting</a></li>
<li><a href="http://www.kavoir.com/2009/11/how-to-recover-lost-firefox-bookmarks-where-is-my-firefox-bookmarks-folder.html" rel="bookmark" title="November 12, 2009">How to recover lost Firefox bookmarks? Where is my Firefox bookmarks folder?</a></li>
</ul>
<p><!-- Similar Posts took 2.646 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2012/01/ffmpeg-delphi-vcl-for-video-audio-applications-development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Get Mime Type of a File (and Encoding)</title>
		<link>http://www.kavoir.com/2011/12/php-get-mime-type-of-a-file-and-encoding.html</link>
		<comments>http://www.kavoir.com/2011/12/php-get-mime-type-of-a-file-and-encoding.html#comments</comments>
		<pubDate>Sun, 25 Dec 2011 04:22:31 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/12/php-get-mime-type-of-a-file-and-encoding.html</guid>
		<description><![CDATA[While you can somewhat rely on the name extension of a file to determine the mime type, it may not always be accurate. For example, .jpg and .jpeg files are very probably image/jpeg files and .png files are very probably image/png files, but there’s always an exception because file extensions can be faked. To accurately [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>While you can somewhat rely on the name extension of a file to determine the mime type, it may not always be accurate. For example, .jpg and .jpeg files are very probably <strong>image/jpeg</strong> files and .png files are very probably <strong>image/png</strong> files, but there’s always an exception because file extensions can be faked. To accurately find the mime type of a specific file in PHP, you should use the <a href="http://www.php.net/manual/en/ref.fileinfo.php">Fileinfo extension</a>.</p>

<p>Find out if the extension is enabled with the code outlined in the beginning part of the <a href="http://www.kavoir.com/2009/01/php-resize-image-and-store-to-file.html">resize image in PHP</a> post.</p>
<p>With the <strong>php_fileinfo</strong> extension enabled in php.ini, this is the function I come up with:</p>
<pre><code>$finfo = new finfo(FILEINFO_MIME); // return mime type
if ($finfo) {
	$file_name = &quot;/absolute/path/to/some.jpg&quot;; /* Must use absolute path */
	$file_info = $finfo-&gt;file($file_name);
	$mime_type = substr($file_info, 0, strpos($file_info, ';'));
	echo $mime_type;
}</code></pre>
<p>Which will get you this:</p>
<pre><code>image/jpeg</code></pre>
<p>The reason it gets complicated in the echo line is that the standard output of FILEINFO_MIME information output by the file() function of the $finfo object is something like this:</p>
<pre><code>image/jpeg; charset=binary</code></pre>
<p>Therefore, you have to literally get everything before the semi-colon to get the mime type information.</p>
<p>If it was a CSS file, the output of the $finfo-&gt;file() method would be like this:</p>
<pre><code>text/plain; charset=utf-8</code></pre>
<p>Cool, huh! <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.kavoir.com/wp-content/uploads/2011/12/wlEmoticon-winkingsmile1.png" /></p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/01/php-resize-image-and-store-to-file.html" rel="bookmark" title="January 15, 2009">PHP: Resize Image and Store to File</a></li>
<li><a href="http://www.kavoir.com/2011/01/linux-how-to-find-only-text-files.html" rel="bookmark" title="January 22, 2011">Linux: How to &#8216;find&#8217; and search ONLY text files?</a></li>
<li><a href="http://www.kavoir.com/2009/01/php-run-html-as-php.html" rel="bookmark" title="January 19, 2009">PHP: Run HTML as PHP</a></li>
<li><a href="http://www.kavoir.com/2009/04/php-get-directory-or-filename-from-a-full-path-or-url.html" rel="bookmark" title="April 22, 2009">PHP: Getting Directory Path and Filename from A Full Path or URL</a></li>
<li><a href="http://www.kavoir.com/2011/05/php-explore-display-contents-of-directory-recursively.html" rel="bookmark" title="May 10, 2011">PHP: Display Files and Sub-directories of A Directory Recursively as A Tree</a></li>
</ul>
<p><!-- Similar Posts took 2.761 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/12/php-get-mime-type-of-a-file-and-encoding.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect 404 Error to Home Page</title>
		<link>http://www.kavoir.com/2011/12/redirect-404-error-to-home-page.html</link>
		<comments>http://www.kavoir.com/2011/12/redirect-404-error-to-home-page.html#comments</comments>
		<pubDate>Sun, 25 Dec 2011 03:15:19 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[CSS & HTML Tips]]></category>
		<category><![CDATA[HTTP Tips & Tutorials]]></category>
		<category><![CDATA[PHP Tips & Tutorials]]></category>
		<category><![CDATA[WordPress How To]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/12/redirect-404-error-to-home-page.html</guid>
		<description><![CDATA[Other than making your 404 error page user friendly, you can redirect it to your index pages such as the homepage, sitemap, or search page, to make it useful for the users. Instead of relying on them to correct the error themselves, you offer the new orientation. How to redirect a 404 error page to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Other than making your <a href="http://www.smashingmagazine.com/2007/08/17/404-error-pages-reloaded/">404 error page</a> <a href="http://www.alistapart.com/articles/perfect404/">user friendly</a>, you can redirect it to your index pages such as the homepage, sitemap, or search page, to make it useful for the users. Instead of relying on them to correct the error themselves, you offer the new orientation.</p>

<h2>How to redirect a 404 error page to the home page?</h2>
<p>There are essentially 3 ways to do this depending on the technology your site is built on.</p>
<h3>The .htaccess and HTML solution</h3>
<p>This works across all sites that are served by the Apache web server with .htaccess enabled. Add this line in the .htaccess file in the root directory of your domain:</p>
<pre><code>ErrorDocument 404 /404.html</code></pre>
<p>And in 404.html, add a meta tag in the HTML head section: </p>
<pre><code>&lt;meta http-equiv=&quot;Refresh&quot; content=&quot;1; URL=http://www.example.com/&quot;&gt;</code></pre>
<p>So when there’s an 404 Not Found error the user would be first redirected to /404.html and in turn, he or she would be redirected to the homepage http://www.example.com/ (or whatever you change it to) by the meta <strong>Refresh</strong> actions.</p>
<h3>The PHP solution</h3>
<p>If you are using PHP to code your site, chances are you know this solution. You can always use the previous solution (The .htaccess and HTML solution) to redirect 404 error page to your home page on a PHP site, but you can also try the pure PHP approach instead.</p>
<p>Whenever a user types in a URL request that you do not recognize, render this:</p>
<pre><code>header(&quot;HTTP/1.1 404 Not Found&quot;);
header(&quot;Location: /&quot;);
exit();</code></pre>
<p>Which would redirect the user who has hit a 404 error to the homepage / or any other page URL you specify there.</p>
<h3>The WordPress solution</h3>
<p>If you are using WordPress for your site, make a 404.php file in your theme directory with the following content:</p>
<pre><code>&lt;?php
header(&quot;HTTP/1.1 301 Moved Permanently&quot;);
header(&quot;Location: &quot;.get_bloginfo('url'));
exit();</code></pre>
<p>WordPress would automatically use 404.php as the default 404 Not Found error page and when a user hits that page, he or she would then be taken to the home page your WordPress blog.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/09/how-to-redirect-the-visitor-to-another-page-or-website.html" rel="bookmark" title="September 3, 2009">How to redirect the visitor to another page or website?</a></li>
<li><a href="http://www.kavoir.com/2009/08/javascript-stop-and-prevent-others-from-framing-your-site-and-page.html" rel="bookmark" title="August 30, 2009">PHP, JavaScript: Stop and prevent others from framing your site or web page</a></li>
<li><a href="http://www.kavoir.com/2011/08/html-make-a-page-refresh-every-xx-seconds.html" rel="bookmark" title="August 28, 2011">HTML: Make a Page Refresh Every xx Seconds</a></li>
<li><a href="http://www.kavoir.com/2009/06/javascript-open-or-redirect-to-another-page-site-location.html" rel="bookmark" title="June 16, 2009">JavaScript: Open or Redirect to Another Page / Site / Location</a></li>
<li><a href="http://www.kavoir.com/2009/09/best-way-to-hide-and-cloak-your-affiliate-links.html" rel="bookmark" title="September 19, 2009">Best way to hide and cloak your affiliate links?</a></li>
</ul>
<p><!-- Similar Posts took 2.985 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/12/redirect-404-error-to-home-page.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Store Array in File &#8211; Read / Write Arrays in File</title>
		<link>http://www.kavoir.com/2011/12/php-store-array-in-file-read-write-arrays-in-file.html</link>
		<comments>http://www.kavoir.com/2011/12/php-store-array-in-file-read-write-arrays-in-file.html#comments</comments>
		<pubDate>Thu, 22 Dec 2011 05:15:34 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/12/php-store-array-in-file-read-write-arrays-in-file.html</guid>
		<description><![CDATA[You can save re-usable data in database such as MySQL so you can load them among different scripts / script sessions, though it may be a bit overwhelming for simple tasks because you have to set up a whole database and the connection credentials, etc.. File system is probably a better approach with regards to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>You can save re-usable data in database such as <a href="http://www.kavoir.com/2011/03/mysql-performance-tips.html">MySQL</a> so you can load them among different scripts / script sessions, though it may be a bit overwhelming for simple tasks because you have to set up a whole database and the connection credentials, etc.. File system is probably a better approach with regards to storing and retrieving simple tabular data, for not-so-important projects or test projects.</p>

<p>Then should we opt for XML or JSON? XML is bit too formal for teensy jobs. <a href="http://www.json.org/">JSON</a>, on the other hand, is the star of simplicity and capable or dealing with both tabular data and objects quite handily.</p>
<p>So we will store tabular data such as an PHP Array to JSON text which would then be stored as a ASCII text file. When we need to use the array again, be it in another PHP script or at a later time, we would just load the JSON string in the file and decode it into an array in PHP.</p>
<p>How can we do this? As simple as abc.</p>
<h2>Store PHP Array in File</h2>
<pre><code>file_put_contents('array.txt', <strong>json_encode</strong>($your_array));</code></pre>
<h2>Read Array from File</h2>
<pre><code>$your_array = <strong>json_decode</strong>(file_get_contents('array.txt'), true);</code></pre>
<h2>Serialize()</h2>
<p>Another approach is to use the <a href="http://php.net/serialize">serialize</a>() and <a href="http://php.net/unserialize">unserialize</a>() functions of PHP. You may want to read this to choose between them: <a href="http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize">http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize</a><br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/04/php-reading-a-file-into-a-string-or-reading-the-file-into-an-array.html" rel="bookmark" title="April 22, 2009">PHP: Reading a File into a String or Reading the File into an Array</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-create-an-array.html" rel="bookmark" title="June 2, 2009">PHP: Create an Array</a></li>
<li><a href="http://www.kavoir.com/2009/06/mysql-php-display-mysql-table-fields-and-data.html" rel="bookmark" title="June 6, 2009">MySQL, PHP: Display MySQL table fields and data</a></li>
<li><a href="http://www.kavoir.com/2009/04/php-randomizing-all-lines-of-a-file-shuffle-lines-in-a-text-file.html" rel="bookmark" title="April 22, 2009">PHP: Randomizing All Lines of a File &ndash; Shuffle Lines in a Text File</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-create-an-array-of-a-range-of-characters-numbers-or-letters-or-multiple-identical-values.html" rel="bookmark" title="June 2, 2009">PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values</a></li>
</ul>
<p><!-- Similar Posts took 2.590 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/12/php-store-array-in-file-read-write-arrays-in-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Crontab Class to Add, Edit and Remove Cron Jobs</title>
		<link>http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html</link>
		<comments>http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html#comments</comments>
		<pubDate>Sun, 30 Oct 2011 02:49:06 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[Free PHP Classes & Library]]></category>
		<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html</guid>
		<description><![CDATA[Provided that your user account on the server has the privileges to access crontab thus can create or remove cron jobs, you can use this PHP class to integrate crontab in your application. I created it for many of my own projects that need crontab to do scheduled jobs. It’s pretty straightforward. Don’t know what [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Provided that your user account on the server has the privileges to access crontab thus can create or remove cron jobs, you can use this PHP class to integrate crontab in your application. I created it for many of my own projects that need crontab to do scheduled jobs. It’s pretty straightforward.</p>

<p>Don’t know what crontab is and how it works? <a href="http://en.wikipedia.org/wiki/Cron">Read here</a> and <a href="http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/">here</a>. With this class, you or your users can easily set up crontab jobs and automate tasks by schedule with the web interface.</p>
<h2>The Crontab Class</h2>
<pre><code>class Crontab {

	// In this class, array instead of string would be the standard input / output format.

	// Legacy way to add a job:
	// $output = shell_exec('(crontab -l; echo &quot;'.$job.'&quot;) | crontab -');

	static private function stringToArray($jobs = '') {
		$array = explode(&quot;\r\n&quot;, trim($jobs)); // trim() gets rid of the last \r\n
		foreach ($array as $key =&gt; $item) {
			if ($item == '') {
				unset($array[$key]);
			}
		}
		return $array;
	}

	static private function arrayToString($jobs = array()) {
		$string = implode(&quot;\r\n&quot;, $jobs);
		return $string;
	}

	static public function <strong>getJobs</strong>() {
		$output = shell_exec('crontab -l');
		return self::stringToArray($output);
	}

	static public function <strong>saveJobs</strong>($jobs = array()) {
		$output = shell_exec('echo &quot;'.self::arrayToString($jobs).'&quot; | crontab -');
		return $output;
	}

	static public function <strong>doesJobExist</strong>($job = '') {
		$jobs = self::getJobs();
		if (in_array($job, $jobs)) {
			return true;
		} else {
			return false;
		}
	}

	static public function <strong>addJob</strong>($job = '') {
		if (self::doesJobExist($job)) {
			return false;
		} else {
			$jobs = self::getJobs();
			$jobs[] = $job;
			return self::saveJobs($jobs);
		}
	}

	static public function <strong>removeJob</strong>($job = '') {
		if (self::doesJobExist($job)) {
			$jobs = self::getJobs();
			unset($jobs[array_search($job, $jobs)]);
			return self::saveJobs($jobs);
		} else {
			return false;
		}
	}

}</code></pre>
<h2>Public Methods</h2>
<p>You may well ignore the private methods that do the internal chores. And keep in mind that <strong>any cron job is a text string</strong>.</p>
<ol>
<li><strong>getJobs</strong>() – returns an array of existing / current cron jobs. Each array item is a string (cron job).</li>
<li><strong>saveJobs</strong>($jobs = array()) – save the $jobs array of cron jobs into the crontab so they would be run by the server. All existing jobs in crontab are erased and replaced by $jobs.</li>
<li><strong>doesJobExist</strong>($job = &#8221;) – check if a specific job exist in crontab.</li>
<li><strong>addJob</strong>($job = &#8221;) – add a cron job to the crontab.</li>
<li><strong>removeJob</strong>($job = &#8221;) – remove a cron job from crontab.</li>
</ol>
<p>This class has been tested on <a href="http://www.rackspacecloudreview.com/">Rackspace Cloud</a> and <a href="http://www.wiredtreereviews.org/">Wiredtree</a>. Feel free to post your comments below and let me know how it works on other <a href="http://www.hostingkids.com/">web hosts</a>.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/08/php-email-attachment-class.html" rel="bookmark" title="August 6, 2009">PHP: Email Attachment Class</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-differences-between-exec-system-and-passthru.html" rel="bookmark" title="June 2, 2009">PHP: Differences between exec(), shell_exec(), system() and passthru()</a></li>
<li><a href="http://www.kavoir.com/2009/01/php-resize-image-and-store-to-file.html" rel="bookmark" title="January 15, 2009">PHP: Resize Image and Store to File</a></li>
<li><a href="http://www.kavoir.com/2010/09/php-checking-text-strings-against-reserved-or-censored-words.html" rel="bookmark" title="September 27, 2010">PHP: Checking Text Strings against Reserved or Censored Words</a></li>
<li><a href="http://www.kavoir.com/2009/01/php-file-upload-class.html" rel="bookmark" title="January 15, 2009">PHP: File Upload Script (HTML Form + PHP Handler Class)</a></li>
</ul>
<p><!-- Similar Posts took 2.916 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/10/php-crontab-class-to-add-and-remove-cron-jobs.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>4 Tips for Zend Studio 8 (Eclipse)</title>
		<link>http://www.kavoir.com/2011/09/3-tips-for-zend-studio-8-eclipse.html</link>
		<comments>http://www.kavoir.com/2011/09/3-tips-for-zend-studio-8-eclipse.html#comments</comments>
		<pubDate>Wed, 14 Sep 2011 06:02:44 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>
		<category><![CDATA[Programming Tips & Insights]]></category>
		<category><![CDATA[Web Applications & Online Software]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/09/3-tips-for-zend-studio-8-eclipse.html</guid>
		<description><![CDATA[I coded a lot in Zend Studio 5.5.1, the gold old version that’s insanely popular because it made it so easy to code in PHP. As PHP evolves, ZS 5.5.1 gradually falls behind of the edge and it simply becomes imperative that you switch to the latest version of Zend Studio, the 8. The IDE [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I coded a lot in Zend Studio 5.5.1, the gold old version that’s insanely popular because it made it so easy to code in PHP. As PHP evolves, ZS 5.5.1 gradually falls behind of the edge and it simply becomes imperative that you switch to the latest version of <a href="http://www.zend.com/products/studio/">Zend Studio</a>, the 8.</p>

<p>The IDE is built on <a href="http://www.eclipse.org/">Eclipse</a>, which I have never used before. It’s great but one still needs some time to learn the curves before he or she can jump in and swim like a whale. Today I gave it a test drive and have some tips to share with you when you are just starting out with Zend Studio 8.</p>
<h2>1. Change Default Character Encoding</h2>
<p>Before you create your project or editing any existing PHP files, you may need to change the default encoding of the Zend Studio Workspace, or make sure it is what you usually work in.</p>
<p>By default, the encoding is that of the container (your operating system). I’m using a Chinese Windows 7 so the default encoding is GBK and it is everything but good because I primarily develop English projects.</p>
<p>For North America users, the default encoding should be ISO-8859-1. If you open up a file that’s encoded in UTF8 without changing the encoding accordingly, you may <a href="http://www.dotvoid.com/2008/10/two-weeks-with-zend-studio-for-eclipse/">end up screwing up the file</a>. And <a href="http://forums.zend.com/viewtopic.php?f=59&amp;t=16388">another victim</a>.</p>
<p>To change the default encoding of Zend Studio: <strong>Windows</strong> –&gt; <strong>Preferences</strong> –&gt; <strong>General</strong> –&gt; <strong>Workspace</strong> –&gt; <strong>Text file encoding</strong>, switch to “Other” and select the encoding you normally use.</p>
<h2>2. Display Function Parameters Hint on Demand</h2>
<p>In 5.5.1, function parameters hint is automatically displayed when you place the cursor in the parentheses. However in 8, the hint is only automatically shown after you immediately finish typing the function name. When the focus moves away or you click anywhere else in the window, the hint disappears and if you don’t know the correct shortcut keys, you wouldn’t be able to get it back.</p>
<p>After a few searches, I found out the key combinations to get the parameters hint re-appear: <strong>Alt + Shift + /</strong></p>
<p><a href="http://files.zend.com/help/Zend-Studio/working_with_code_assist.htm#MiniTOCBookMark4">Some pages</a> say it’s <strong>Ctrl + Shift + Space</strong> but it didn’t work out for me. Maybe it’s a version thing?</p>
<h2>3. Display Potential Function Candidates / Auto-complete Function Names</h2>
<p>Along with the previous tip, this one is pretty important in modern IDE because they are essential in boosting one’s coding productivity. Can’t live without them.</p>
<p>When you are typing the function name, Zend Studio would guess what you mean and display a list of possible candidates for you to choose from.</p>
<p>If you want it to appear again, just place the cursor on the function name and use <strong>Alt + /</strong> to make Zend Studio makes a guess again.</p>
<h2>4. Display All Shortcut Key Combinations</h2>
<p>You can use a lot of shortcut keys in Zend Studio 8 to make things happen quickly and intuitively, just press <strong>Ctrl + Shift + L</strong> to bring up the key map to see the full list. Here&#8217;s a list of the commonly used commands:</p>
<p><a href="http://www.kavoir.com/wp-content/uploads/2011/09/zend-studio-keymap.png" rel="lightbox[2336]" title="4 Tips for Zend Studio 8 (Eclipse)"><img class="alignnone size-full wp-image-2345" src="http://www.kavoir.com/wp-content/uploads/2011/09/zend-studio-keymap.png" alt="zend studio 8 key assist - commonly used commands" width="600" height="738" /></a><br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/06/work-around-zend-studio-5-5-php-class-object-method-auto-complete-problem.html" rel="bookmark" title="June 20, 2009">Work Around Zend Studio 5.5 PHP Class / Object / Method Auto-complete Problem</a></li>
<li><a href="http://www.kavoir.com/2011/02/www-gmail-com.html" rel="bookmark" title="February 20, 2011">www.gmail.com &#8211; Tips</a></li>
<li><a href="http://www.kavoir.com/2009/06/php-change-array-key-case-all-array-keys-to-lowercase-or-uppercase.html" rel="bookmark" title="June 2, 2009">PHP: Change Array Key Case &#8211; All Array Keys to Lowercase or Uppercase</a></li>
<li><a href="http://www.kavoir.com/2009/08/one-simple-way-to-encrypt-obfuscate-hide-or-protect-your-php-code.html" rel="bookmark" title="August 4, 2009">One Simple Way to Encrypt, Obfuscate, Hide or Protect Your PHP Code</a></li>
<li><a href="http://www.kavoir.com/2012/01/customize-wordpress-post-editor-css-styles.html" rel="bookmark" title="January 19, 2012">Customize WordPress Post Editor CSS Styles</a></li>
</ul>
<p><!-- Similar Posts took 2.717 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/09/3-tips-for-zend-studio-8-eclipse.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Display Files and Sub-directories of A Directory Recursively as A Tree</title>
		<link>http://www.kavoir.com/2011/05/php-explore-display-contents-of-directory-recursively.html</link>
		<comments>http://www.kavoir.com/2011/05/php-explore-display-contents-of-directory-recursively.html#comments</comments>
		<pubDate>Tue, 10 May 2011 07:35:23 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/05/php-explore-display-contents-of-directory-recursively.html</guid>
		<description><![CDATA[Given a directory, how to display the contents (directories and files under it) of it recursively and exhaustively? Here’s the code: $dir = '/path/to/directory'; // without trailing slash, can be absolute paths such as '/home/jim/public_html' or relative paths such as 'samples' getDirContents($dir); function getDirContents($dir) { if (is_dir($dir)) { $dirs = explode('/', $dir); $last_dir = $dirs[count($dirs) [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Given a directory, how to display the contents (directories and files under it) of it recursively and exhaustively? Here’s the code:<span id="more-2239"></span></p>
<pre><code>$dir = '/path/to/directory'; // without trailing slash, can be absolute paths such as '/home/jim/public_html' or relative paths such as 'samples'

<strong>getDirContents</strong>($dir);

function <strong>getDirContents</strong>($dir) {
	if (is_dir($dir)) {
		$dirs = explode('/', $dir);
		$last_dir = $dirs[count($dirs) - 1];
		echo '&lt;strong&gt;'.$last_dir.'&lt;/strong&gt;';
	    if ($dh = opendir($dir)) {
	    	echo '&lt;ul&gt;';
	        while (($file = readdir($dh)) !== false) {
	        	if ($file == '.' || $file == '..') {} else {
		        	echo '&lt;li&gt;';
		        	if (<strong>is_dir</strong>($dir.'/'.$file)) {
		        		<strong>getDirContents</strong>($dir.'/'.$file);
		        	} else {
		        		echo $file;
		        	}
		        	echo '&lt;/li&gt;';
	        	}
	        }
	        echo '&lt;/ul&gt;';
	        closedir($dh);
	    }
	}
	return false;
}</code></pre>
<p>Recursively, the function <strong>getDirContents</strong>() explores every entry in the directory. If the entry is a file, it simply prints it; if it is a directory, it opens another subroutine of itself to explore that directory; and so forth, until every branch and sub-branches, etc. are all printed out.<br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2010/08/how-to-get-all-the-sub-directories-of-a-given-directory-in-php.html" rel="bookmark" title="August 1, 2010">How to get all the sub-directories of a given directory in PHP?</a></li>
<li><a href="http://www.kavoir.com/2010/05/simplest-php-hit-counter-or-download-counter-count-the-number-of-times-of-access-visits-or-downloads.html" rel="bookmark" title="May 19, 2010">Simplest PHP Hit Counter or Download Counter &ndash; Count the Number of Times of Access (Page Views or File Downloads)</a></li>
<li><a href="http://www.kavoir.com/2009/04/php-reading-a-file-into-a-string-or-reading-the-file-into-an-array.html" rel="bookmark" title="April 22, 2009">PHP: Reading a File into a String or Reading the File into an Array</a></li>
<li><a href="http://www.kavoir.com/2009/09/linux-check-how-much-disk-storage-each-directory-takes-up-disk-usage-command-du.html" rel="bookmark" title="September 2, 2009">Linux: Check how much disk storage each directory takes up (Disk Usage command &#8211; du)</a></li>
<li><a href="http://www.kavoir.com/2009/04/php-open-remote-file.html" rel="bookmark" title="April 22, 2009">PHP: Open Remote File</a></li>
</ul>
<p><!-- Similar Posts took 2.484 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/05/php-explore-display-contents-of-directory-recursively.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Performance Tips</title>
		<link>http://www.kavoir.com/2011/03/mysql-performance-tips.html</link>
		<comments>http://www.kavoir.com/2011/03/mysql-performance-tips.html#comments</comments>
		<pubDate>Sat, 12 Mar 2011 03:49:50 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[SQL / MySQL Tips and Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/03/mysql-performance-tips.html</guid>
		<description><![CDATA[I’m not an expert but I’ve had my own errors and trials along the way so here I am. These are all the tips I believe you should use when you are optimizing for MySQL database performance. Some stuff may be very handy, but they may not be good for performance. Design Normalize first, and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignright size-full wp-image-2368" title="MySQL" src="http://www.kavoir.com/wp-content/uploads/2011/03/MySQL.png" alt="MySQL" width="110" height="57" />I’m not an expert but I’ve had my own errors and trials along the way so here I am. These are all the tips I believe you should use when you are optimizing for MySQL database performance. Some stuff may be very handy, but they may not be good for performance.<span id="more-2180"></span></p>
<h2>Design</h2>
<ol>
<li>Normalize first, and de-normalize where appropriate. Table joins are never lags in performance. Use them!</li>
<li>Choose the appropriate collation / charset. UTF16 is omnipotent but it requires 2 times the storage. UTF8 delivers more characters but it’s slower than latin1. Unless it’s necessary, use latin1.</li>
<li><strong>utf8_general_ci</strong> is slightly faster than utf8_unicode_ci, thus better in performance.</li>
<li>Use <strong>NOT NULL</strong> wherever possible.</li>
<li>Use indexes. Create indexes by analyzing the SELECTs you are doing on the table.</li>
<li><strong>Indexing</strong> increases performance in <strong>selecting</strong>, yet decreases performance in <strong>inserting</strong>. So don’t index everything but only those necessary. And don’t make duplicate indexes.</li>
</ol>
<h2>Querying</h2>
<ol>
<li>Use smallest data types possible.</li>
<li><strong>IN (…)</strong> is a total fail. Avoid it wherever possible.</li>
<li><strong>ORDER BY RAND()</strong> is a fail too.</li>
<li>When you need to SELECT … to make sure there’s no duplicate unique index values before inserting something, use <strong>INSERT … ON DUPLICATE KEY UPDATE …</strong> instead.</li>
<li>If your app writes a lot, use InnoDB; if it reads a lot, use MyISAM. Here’s a <a href="http://www.kavoir.com/2009/09/mysql-engines-innodb-vs-myisam-a-comparison-of-pros-and-cons.html">comparison</a>.</li>
<li>Never use <strong>LIMIT xxxx1, xxxx2</strong> with large tables especially when offset xxxx1 is a pretty large number. Instead, give a more strict <strong>WHERE …</strong> clause with <strong>LIMIT xxxx2</strong>.</li>
<li>If a feature is deprecated, stop using it.</li>
<li>Avoid wildcards % or _ at the beginning of LIKE queries, e.g. LIKE ‘%bloom’ – this should be avoided. For instance, you should store email addresses reversed (REVERSED()) so it’s faster to search by domain.</li>
<li>If you have a large set of data rows to be inserted at once, create a combined INSERT query string in PHP first – that is, to bulk insert them in batches rather than one by one. LOAD DATA is also a better option than individual INSERT.</li>
<li>Prefer <strong>GROUP BY</strong> over DISTINCT.</li>
<li>Frequently visit <a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html">Slow Query Log</a>.</li>
<li>Avoid calculated values in WHERE … , LIMIT … , ORDER BY … , etc.</li>
<li>Use <strong>EXPLAIN …</strong> to get an idea of how MySQL is doing with your queries thus better optimize it. For example, it would suggest the indexes you should have created.</li>
<li>Don’t <strong>SELECT * …</strong> on everything, SELECT only what you need.</li>
<li>Be wary of lots of small queries that may be triggered in loops. Instead, combine them and use one large query wherever possible.</li>
</ol>
<h2>Storage Engines</h2>
<ol>
<li>Know the pros and cons of different storage engines and use them accordingly. But try them out in the test environment before making the decision.</li>
<li>Archive old data such as logs in ARCHIVE tables or MERGE tables.</li>
<li>BLACKHOLE engine is very fast for busy things like logs.</li>
</ol>
<h2>my.ini</h2>
<ol>
<li>Increase the default key buffer size: <strong>key_buffer = 128M</strong></li>
<li>Increase the default number of tables that can be kept open: <strong>table_cache = 128</strong></li>
<li>Increase the default sort buffer size:<br />
<strong>sort_buffer_size = 32M</strong><br />
<strong>myisam_sort_buffer_size = 32M</strong></li>
<li>Disable binary logging that is for data replication by commenting out the line like this:  <strong># log-bin=mysql-bin</strong></li>
</ol>
<h2>What to read from here:</h2>
<ol>
<li>Indexing: <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html">http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html</a></li>
<li>“LIMIT” Optimization: <a href="http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html">http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html</a></li>
<li>“ORDER BY” Optimization<a href="http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html">http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html</a></li>
<li>Efficient Paging: <a href="http://www.slideshare.net/suratbhati/efficient-pagination-using-mysql-6187107">http://www.slideshare.net/suratbhati/efficient-pagination-using-mysql-6187107</a></li>
<li>Configuration Tweaks: <a href="http://docs.cellblue.nl/2007/03/17/easy-mysql-performance-tweaks/">http://docs.cellblue.nl/2007/03/17/easy-mysql-performance-tweaks/</a></li>
</ol>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/05/mysql-huge-table-not-responding-after-adding-index.html" rel="bookmark" title="May 18, 2009">MySQL: Huge Table Not Responding after Adding Index</a></li>
<li><a href="http://www.kavoir.com/2009/04/mysql-id-between-start-and-end-instead-of-limit-start-step-for-better-database-performance.html" rel="bookmark" title="April 12, 2009">MySQL: id BETWEEN start AND end Instead of LIMIT start, step For Better Database Performance</a></li>
<li><a href="http://www.kavoir.com/2011/03/mysql-get-the-exact-size-of-a-database-by-query.html" rel="bookmark" title="March 5, 2011">MySQL: Get the exact size of a database by SQL query</a></li>
<li><a href="http://www.kavoir.com/2009/05/mysql-insert-if-doesnt-exist-otherwise-update-the-existing-row.html" rel="bookmark" title="May 2, 2009">MySQL: Insert if doesn&rsquo;t exist otherwise update the existing row</a></li>
<li><a href="http://www.kavoir.com/2009/05/mysql-insert-into-select-from.html" rel="bookmark" title="May 13, 2009">MySQL: INSERT INTO &hellip; SELECT &hellip; FROM &hellip; Selectively on Table Columns / Fields to Combine Multiple Tables into One</a></li>
</ul>
<p><!-- Similar Posts took 2.944 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/03/mysql-performance-tips.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL: Get the exact size of a database by SQL query</title>
		<link>http://www.kavoir.com/2011/03/mysql-get-the-exact-size-of-a-database-by-query.html</link>
		<comments>http://www.kavoir.com/2011/03/mysql-get-the-exact-size-of-a-database-by-query.html#comments</comments>
		<pubDate>Sat, 05 Mar 2011 02:13:45 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[SQL / MySQL Tips and Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/03/mysql-get-the-exact-size-of-a-database-by-query.html</guid>
		<description><![CDATA[phpMyAdmin doesn’t show the exact size in MB when the size of your database exceeds 1GB. It just shows something like 4.2GB, truncating everything out in the 100MB precision. So is it possible to get the database size in MB in exact numbers using MySQL query? Yes, it is: SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>phpMyAdmin doesn’t show the exact size in MB when the size of your database exceeds 1GB. It just shows something like 4.2GB, truncating everything out in the 100MB precision. So is it possible to get the database size in MB in exact numbers using MySQL query?</p>

<p>Yes, it is:</p>
<pre><code>SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '<strong>YOUR_DATABASE_NAME_HERE</strong>%' ;</code></pre>
<p>Just change <strong>YOUR_DATABASE_NAME_HERE</strong> into the name of your database. And it would prints out something like this:</p>
<pre><code>+------------+
| Size       |
+------------+
| 4906.79 MB |
+------------+
1 row in set (0.05 sec)</code></pre>
<p>You can also get the size of a specific table. Read here: <a href="http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query">http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query</a><br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2010/07/mysql-check-if-a-table-exists.html" rel="bookmark" title="July 30, 2010">MySQL: Check if a table exists</a></li>
<li><a href="http://www.kavoir.com/2009/09/mysql-select-and-show-all-mysql-users.html" rel="bookmark" title="September 3, 2009">MySQL: Select and Show all MySQL Users</a></li>
<li><a href="http://www.kavoir.com/2009/06/mysql-php-store-form-textarea-value-to-mysql-database-table.html" rel="bookmark" title="June 6, 2009">MySQL, PHP: Store form textarea value or data to MySQL database table</a></li>
<li><a href="http://www.kavoir.com/2009/06/mysql-php-display-mysql-table-fields-and-data.html" rel="bookmark" title="June 6, 2009">MySQL, PHP: Display MySQL table fields and data</a></li>
<li><a href="http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html" rel="bookmark" title="February 17, 2011">MySQL: How to export a database / table to XML?</a></li>
</ul>
<p><!-- Similar Posts took 2.572 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/03/mysql-get-the-exact-size-of-a-database-by-query.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Find non-ASCII characters in a table column</title>
		<link>http://www.kavoir.com/2011/03/mysql-find-non-ascii-characters.html</link>
		<comments>http://www.kavoir.com/2011/03/mysql-find-non-ascii-characters.html#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:54:28 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[SQL / MySQL Tips and Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/03/mysql-find-non-ascii-characters.html</guid>
		<description><![CDATA[ASCII is the most fundamental character set that has been around since the early days of command line interfaces. There are 128 (0 &#8211; 127) most basic ASCII characters such as a-z, A-Z, 0-9, and all the printable punctuations you can type out by a single strike of your keyboard. As all ASCII characters have [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>ASCII is the most fundamental character set that has been around since the early days of command line interfaces. There are 128 (0 &#8211; 127) most basic ASCII characters such as a-z, A-Z, 0-9, and all the printable punctuations you can type out by a single strike of your keyboard.</p>

<p>As all ASCII characters have an internal decimal value of 0 – 127, which is 0&#215;00 – 0x0F in heximal values, you can find all the non-ASCII characters in <em>my_column</em> by query:</p>
<pre><code>SELECT * FROM my_table WHERE <strong>NOT HEX(my_column) REGEXP '^([0-7][0-9A-F])*$'</strong>;</code></pre>
<p>On the other hand, if you wish to find all records that a certain column (<em>my_column</em>) contains ASCII characters:</p>
<pre><code>SELECT * FROM my_table WHERE <strong>HEX(my_column) REGEXP '^([0-7][0-9A-F])*$'</strong>;</code></pre>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/05/mysql-deleting-duplicate-rows-or-records-selecting-unique-rows-into-a-new-table.html" rel="bookmark" title="May 16, 2009">MySQL: Deleting Duplicate Rows or Records | Selecting Unique Rows into A New Table</a></li>
<li><a href="http://www.kavoir.com/2009/05/mysql-find-duplicate-entry-rows-records.html" rel="bookmark" title="May 19, 2009">MySQL: Find Duplicate Entry / Rows / Records</a></li>
<li><a href="http://www.kavoir.com/2009/01/sql-insert-into-select-to-generate-or-combine-records-from-existing-ones-and-insert-into-an-existing-table.html" rel="bookmark" title="January 4, 2009">SQL: INSERT INTO … SELECT … to generate or combine records from existing ones and insert into an existing table</a></li>
<li><a href="http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html" rel="bookmark" title="May 17, 2009">MySQL: Update Multiple Rows or Records with One Single Query</a></li>
<li><a href="http://www.kavoir.com/2009/01/sql-create-table-select-to-generate-new-table-from-existing-tables.html" rel="bookmark" title="January 4, 2009">SQL: CREATE TABLE &#8230; SELECT &#8230; to generate new table from existing tables</a></li>
</ul>
<p><!-- Similar Posts took 2.721 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/03/mysql-find-non-ascii-characters.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: How to export a database / table to XML?</title>
		<link>http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html</link>
		<comments>http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html#comments</comments>
		<pubDate>Thu, 17 Feb 2011 15:59:49 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[SQL / MySQL Tips and Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html</guid>
		<description><![CDATA[You can export any MySQL database or table into an XML file by the exporting capabilities of phpMyAdmin, the web interface of MySQL. The problem with this approach, however, is that with large tables, you may have to manually export the table more than once by sections into several sequential XML files. A better approach [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>You can export any MySQL database or table into an XML file by the exporting capabilities of <a href="http://www.phpmyadmin.net">phpMyAdmin</a>, the web interface of MySQL. The problem with this approach, however, is that with large tables, you may have to manually export the table more than once by sections into several sequential XML files.</p>

<p>A better approach is by native MySQL command line that will create and store all entries of the table into one XML file:</p>
<pre><code>mysql -u <strong>db_user</strong> -p <strong>db_name</strong> --xml -e &quot;SELECT * FROM <strong>table_name</strong>&quot; &gt; <strong>table_name.xml</strong></code></pre>
<p>Wherein <strong>db_user</strong> is your MySQL server user, <strong>db_name</strong> is the name of the database and <strong>table_name</strong> is the name of the table that you would like exported to XML. The resulted XML will be stored in <strong>table_name.xml</strong>. </p>
<p>Note that this is different from <a href="http://www.kavoir.com/2009/09/mysql-how-to-backup-all-databases-at-once-as-root-with-mysqldump.html">mysqldump</a> in that it’s basically executing a query by the –e switch and output the results in XML (&#8211;xml). The results is then directed to the out file rather than displayed on terminal screen.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2009/09/mysql-how-to-backup-all-databases-at-once-as-root-with-mysqldump.html" rel="bookmark" title="September 5, 2009">MySQL: How to backup ALL databases as root with mysqldump at once?</a></li>
<li><a href="http://www.kavoir.com/2008/12/backup-and-recover-a-mysql-database-under-command-line.html" rel="bookmark" title="December 14, 2008">Backup and recover a MySQL database under command line</a></li>
<li><a href="http://www.kavoir.com/2009/04/mysql-id-between-start-and-end-instead-of-limit-start-step-for-better-database-performance.html" rel="bookmark" title="April 12, 2009">MySQL: id BETWEEN start AND end Instead of LIMIT start, step For Better Database Performance</a></li>
<li><a href="http://www.kavoir.com/2010/11/mysql-export-table-to-csv-text-files-for-excel.html" rel="bookmark" title="November 18, 2010">MySQL: Export Table to CSV Text Files for Excel</a></li>
<li><a href="http://www.kavoir.com/2009/06/reset-mysql-root-password-after-you-forgot-or-lost-it.html" rel="bookmark" title="June 20, 2009">How to Recover or Reset MySQL root Password after You Forgot and Lost It</a></li>
</ul>
<p><!-- Similar Posts took 2.829 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2011/02/mysql-how-to-export-a-database-table-to-xml.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checklist slides to learn the new features in PHP 5.3 with examples</title>
		<link>http://www.kavoir.com/2010/12/checklist-slides-to-learn-new-features-in-php-5-3.html</link>
		<comments>http://www.kavoir.com/2010/12/checklist-slides-to-learn-new-features-in-php-5-3.html#comments</comments>
		<pubDate>Fri, 10 Dec 2010 14:31:45 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[PHP Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2010/12/checklist-slides-to-learn-new-features-in-php-5-3.html</guid>
		<description><![CDATA[One of my old Internet friends Brad made a very nice online slide that introduces to you some of the exciting new features of PHP 5.3. I&#8217;m most interested in namespace that would make coding in a large project and code reuse much easier, especially for people who find keeping naming conventions a challenge in [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>One of my old Internet friends Brad made a very nice online slide that introduces to you some of the exciting new features of PHP 5.3. I&#8217;m most interested in namespace that would make coding in a large project and code reuse much easier, especially for people who find keeping naming conventions a challenge in the team.</p>

<p>Here&#8217;s the original post and slide: <a href="http://bradley-holt.com/2010/11/new-features-in-php-53/">http://bradley-holt.com/2010/11/new-features-in-php-53/</a></p>
<div id="__ss_5827399" style="width: 425px;"><strong><a title="New Features in PHP 5.3" href="http://www.slideshare.net/bradley.holt/new-features-in-php-53">New Features in PHP 5.3</a></strong><object id="__sse5827399" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newfeaturesinphp5-3-101118145553-phpapp01&amp;stripped_title=new-features-in-php-53&amp;userName=bradley.holt" /><param name="name" value="__sse5827399" /><param name="allowfullscreen" value="true" /><embed id="__sse5827399" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newfeaturesinphp5-3-101118145553-phpapp01&amp;stripped_title=new-features-in-php-53&amp;userName=bradley.holt" name="__sse5827399" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 12px; padding-top: 5px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/bradley.holt">Bradley Holt</a>.</div>
</div>
<p>All the new stuff and concepts are presented in a practical manner that&#8217;s extremely straightforward. Programmers should find them a breeze to crunch.<br />
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2011/07/microsoft-office-365-review-screenshots-what-will-you-get.html" rel="bookmark" title="July 15, 2011">Microsoft Office 365 Review &#038; Screenshots &#8211; What will you get?</a></li>
<li><a href="http://www.kavoir.com/2009/08/one-simple-way-to-encrypt-obfuscate-hide-or-protect-your-php-code.html" rel="bookmark" title="August 4, 2009">One Simple Way to Encrypt, Obfuscate, Hide or Protect Your PHP Code</a></li>
<li><a href="http://www.kavoir.com/2009/07/be-simple.html" rel="bookmark" title="July 6, 2009">Being simple as a bless for development cost</a></li>
<li><a href="http://www.kavoir.com/2010/03/use-relative-protocol-url-address-to-automatically-determine-web-address-protocol-http-or-https.html" rel="bookmark" title="March 6, 2010">Use Relative Protocol URL Address to Automatically Determine Web Address Protocol (HTTP or HTTPS)</a></li>
<li><a href="http://www.kavoir.com/2010/09/free-php-business-directory-script.html" rel="bookmark" title="September 29, 2010">Free PHP Business Directory Script</a></li>
</ul>
<p><!-- Similar Posts took 2.820 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2010/12/checklist-slides-to-learn-new-features-in-php-5-3.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A small mistake in a regular expression caused connection to reset &#8211; (.+)+</title>
		<link>http://www.kavoir.com/2010/12/a-small-mistake-in-a-regular-expression-caused-connection-to-reset.html</link>
		<comments>http://www.kavoir.com/2010/12/a-small-mistake-in-a-regular-expression-caused-connection-to-reset.html#comments</comments>
		<pubDate>Sat, 04 Dec 2010 06:42:02 +0000</pubDate>
		<dc:creator>Yang Yang</dc:creator>
				<category><![CDATA[Regular Expression Tips & Tutorials]]></category>

		<guid isPermaLink="false">http://www.kavoir.com/2010/12/a-small-mistake-in-a-regular-expression-caused-connection-to-reset.html</guid>
		<description><![CDATA[Was doing something with a regular expression and very oddly the connection keeps being reset every time I refresh the web page. I tried to narrow down the problematic line by removing the code in functional chunks. Finally it comes down to a preg_match() instance with a small bit in the regular expression that&#8217;s accidentally [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Was doing something with a regular expression and very oddly the connection keeps being reset every time I refresh the web page.</p>

<p>I tried to narrow down the problematic line by removing the code in functional chunks. Finally it comes down to a preg_match() instance with a small bit in the regular expression that&#8217;s accidentally and wrongly typed in caught my attention:</p>
<pre><code>(.+)+</code></pre>
<p>Got rid of the second plus sign:</p>
<pre><code>(.+)</code></pre>
<p>And it&#8217;s all right.</p>
<h3>Related Posts:</h3>
<ul class="similar-posts">
<li><a href="http://www.kavoir.com/2010/09/regular-expression-for-natural-numbers-or-positive-integers-1-2-3-11-12.html" rel="bookmark" title="September 29, 2010">Regular Expressions for Natural Numbers or Positive Integers (1, 2, 3, &hellip;), Negative Integers and Non-negative Integers</a></li>
<li><a href="http://www.kavoir.com/2009/12/php-regular-expression-matching-input-subject-string-length-limit.html" rel="bookmark" title="December 12, 2009">PHP: Subject String Length Limit of Regular Expression Matching Functions</a></li>
<li><a href="http://www.kavoir.com/2010/09/regular-expression-for-date-and-time-strings.html" rel="bookmark" title="September 29, 2010">Regular Expression for Date and Time Strings</a></li>
<li><a href="http://www.kavoir.com/2009/01/using-javascript-to-refresh-and-reload-an-iframe-on-main-page.html" rel="bookmark" title="January 1, 2009">Using JavaScript to refresh and reload an iframe on main page</a></li>
<li><a href="http://www.kavoir.com/2010/03/php-check-or-validate-url-and-email-addresses-an-easier-way-than-regular-expressions-the-filter_var-function.html" rel="bookmark" title="March 4, 2010">PHP: Check or Validate URL and Email Addresses &ndash; an Easier Way than Regular Expressions, the filter_var() Function</a></li>
</ul>
<p><!-- Similar Posts took 2.581 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kavoir.com/2010/12/a-small-mistake-in-a-regular-expression-caused-connection-to-reset.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

