<?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>Evolvan</title>
	<atom:link href="http://evolvan.com/feed" rel="self" type="application/rss+xml" />
	<link>http://evolvan.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 12 Mar 2013 05:13:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How session_start() works in PHP</title>
		<link>http://evolvan.com/session-start-function-working-in-php</link>
		<comments>http://evolvan.com/session-start-function-working-in-php#comments</comments>
		<pubDate>Mon, 15 Oct 2012 12:34:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=481</guid>
		<description><![CDATA[Before starting we should know some terms below Session cookie is key code which is generated by server and helps the server to identify the computer on the internet. Session cookie is stored locally in the client browser. Now lets see exactly how it works session_start( ) function  is always located on the top of [...]]]></description>
				<content:encoded><![CDATA[<p>Before starting we should know some terms below</p>
<ul style="margin-left:30px">
<li><strong>Session cookie</strong> is key code which is generated by server and helps the server to identify the computer on the internet.</li>
<li><strong>Session cookie</strong> is stored locally in the client browser.</li>
</ul>
<p><strong><span style="text-decoration: underline;">Now lets see exactly how it works </span></strong></p>
<p style="text-align: center;"><a href="http://evolvan.com/wp-content/uploads/2012/10/session-start-function-working-in-php.jpg" rel="prettyPhoto[481]"><img class="alignnone size-full wp-image-485" title="session-start-function-working-in-php" src="http://evolvan.com/wp-content/uploads/2012/10/session-start-function-working-in-php.jpg" alt="" width="478" height="725" /></a></p>
<ul style="margin-left:30px">
<li><strong>session_start( )</strong> function  is always located on the top of the <strong>php page</strong> . Its first function is to check whether the Prior <strong>session cookie</strong> is existed, on the client browser or not.</li>
</ul>
<ul style="margin-left:30px">
<li>If <strong>session_start( )</strong> function did not find any <strong>session cookie</strong> in the client browser , It sends the request to the Server there is no <strong>session cookie</strong> existed in the client browser , Then in the respond the server send new generated <strong>session cookie</strong> for the client computer.</li>
</ul>
<ul style="margin-left:30px">
<li>If <strong>session_start( )</strong> function finds the <strong>session cookie</strong> in the client browser  ,Then it checks the expiration date of it .</li>
</ul>
<ul style="margin-left:30px">
<li> If <strong>session cookie</strong> is expired by the server , then <strong>session_start() </strong>function request the server and server immediately  generate new <strong>session cookie</strong> for the client computer.</li>
</ul>
<ul style="margin-left:30px">
<li>If  it  is not expired by Server , then server shows the temporary data regarding that <strong>session cookie</strong> ,on  the client computer.</li>
</ul>
<ul style="margin-left:30px">
<li> The <strong>session cookie</strong> is used to initialize the  <strong>$_SESSION( )</strong> .</li>
</ul>
<p><strong> </strong></p>
<p>If you want to learn more you can join our Php Professional Training Course <a title="PHP Training In Ludhiana" href="http://evolvan.com/php-professional-training" target="_blank">Php Training In Ludhiana</a></p>
]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/session-start-function-working-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Professional Training</title>
		<link>http://evolvan.com/php-professional-training</link>
		<comments>http://evolvan.com/php-professional-training#comments</comments>
		<pubDate>Thu, 13 Sep 2012 09:38:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=474</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/php-professional-training/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ext.Ajax: Creating global listeners</title>
		<link>http://evolvan.com/blog/ext-ajax-creating-global-listeners</link>
		<comments>http://evolvan.com/blog/ext-ajax-creating-global-listeners#comments</comments>
		<pubDate>Sun, 15 Jul 2012 12:12:18 +0000</pubDate>
		<dc:creator>taj</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ExtJs]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=440</guid>
		<description><![CDATA[I started developing an application using ExtJs (of course) and at some point, after writing thousands of lines of code, having hundreds of ajax calls, it occurred to me that I want to perform an action against every ajax call. So, the requirements were: 1. If user action has initiated an Ajax call but user [...]]]></description>
				<content:encoded><![CDATA[<p>I started developing an application using ExtJs (of course) and at some point, after writing thousands of lines of code, having hundreds of ajax calls, it occurred to me that I want to perform an action against every ajax call.</p>
<p>So, the requirements were:<br />
1. If user action has initiated an Ajax call but user session is expired (server returns 401 in this case), UI should show an alert. On this alert when user click on &#8220;OK&#8221; it should redirect user to login page.<br />
2. It must also suppress any defined &#8216;failure&#8217; handler for the corresponding ajax call.</p>
<p>Changing all ajax calls and adding appropriate conditions to &#8216;failure&#8217; functions was going to be a tedious job. I came across a way to add global listeners which will be applicable for all ajax calls made through the application. I was having a js file which was being included in all views, so I added following code in that file:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">Ajax</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'requestexception'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>conn<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">status</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">401</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Ext.<span style="color: #660066;">Msg</span>.<span style="color: #660066;">alert</span><span style="color: #009900;">&#40;</span>
        <span style="color: #3366CC;">&quot;Login session expired&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Your log-in session has expired&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>btn<span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/login'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This solved (1) above but the &#8216;failure&#8217; defined for the ajax call was also getting executed. I found no way to purge those listeners (I tried purgeListeners() and abort()). With some further investigation I found a way to redefine the &#8216;failure&#8217; function. So, the code looked like:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"> Ext.<span style="color: #660066;">Ajax</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'requestexception'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>conn<span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> options<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>response.<span style="color: #660066;">status</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">401</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      options.<span style="color: #660066;">failure</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*do nothing*/</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      Ext.<span style="color: #660066;">Msg</span>.<span style="color: #660066;">alert</span><span style="color: #009900;">&#40;</span>
        <span style="color: #3366CC;">&quot;Login session expired&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #3366CC;">&quot;Your log-in session has expired.&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>btn<span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            window.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/login'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This solved (2) above. </p>
<p>So far I am happy with this solution. Why? Because it solved the purpose <img src='http://evolvan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hope it will be helpful for you if you got stuck in similar scenario.</p>
<p>Ref. <a href="http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Ajax-event-requestexception">http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Ajax-event-requestexception</a></p>
]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/blog/ext-ajax-creating-global-listeners/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDO for Database Access</title>
		<link>http://evolvan.com/blog/pdo-database-access</link>
		<comments>http://evolvan.com/blog/pdo-database-access#comments</comments>
		<pubDate>Wed, 04 Jul 2012 13:09:07 +0000</pubDate>
		<dc:creator>paw</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=411</guid>
		<description><![CDATA[ “PDO – PHP Data Objects &#8211; is a PHP extension that allows developers to create code which is portable across many databases.” What does that mean? That means we can develop a code (using PDO) which is independent of what database server is being used. So, the script written, using PDO can work with MySql [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size: 1.3em; margin-top: 30px;">
<blockquote><p> “PDO – PHP Data Objects &#8211; is a PHP extension that allows developers to create code which is portable across many databases.”</p></blockquote>
<h4>What does that mean?</h4>
<p>That means we can develop a code (using PDO) which is independent of what database server is being used. So, the script written, using PDO can work with MySql at one point and InterBase at other and so do for PostgreSQL, Oracle and many more.</p>
<h4>How to install PDO?</h4>
<p>First of all you need to install correct PDO driver for the database server you are going to use. For MySQL we must enable PHP_PDO_MYSQL extension in php settings.</p>
<p>Check phpinfo(), to see if the PDO driver is available for your database, and you should have a section named PDO and another pdo_mysql or pdo_sqlite depending on your choice. You can also use below static method for available drivers in php.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
PDO<span style="color: #339933;">::</span><span style="color: #004000;">getAvailableDrivers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<h4>What databases are supported by PDO?</h4>
<ol style="margin: 20px 0 0 40px;">
<li>DBLIB: FreeTDS / Microsoft SQL Server / Sybase</li>
<li>Firebird : Firebird/Interbase 6</li>
<li>IBM (IBM DB2)</li>
<li>INFORMIX &#8211; IBM Informix Dynamic Server</li>
<li>MYSQL : MySQL 3.x/4.0</li>
<li>OCI : Oracle Call Interface</li>
<li>ODBC: ODBC v3 (IBM DB2 and unixODBC)</li>
<li>PGSQL : PostgreSQL</li>
<li>SQLITE : SQLite 3.x</li>
</ol>
<p>&nbsp;</p>
<h4>Let us see how we can connect with different databases using PDO?</h4>
<p><span style="color: #808080;">//Oracle</span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OCI:dbname=accounts;charset=UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="color: #808080;">//ODBC</span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="color: #808080;">//Mysql</span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$hostname</span>;dbname=mysql&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>&nbsp;</p>
<h4>PDO fetch types like mysql_fetch_array, mysql_fetch_object.</h4>
<p>&nbsp;<br />
<strong>PDO::FETCH_ASSOC</strong>: Returns an array indexed by column name.<br />
<strong>PDO::FETCH_BOTH</strong> (default): Returns an array indexed by both column name and 0-indexed column number.<br />
<strong>PDO::FETCH_NUM</strong>: Returns an array indexed by column number.<br />
<strong>PDO::FETCH_OBJ</strong>: Returns an anonymous object with property names that correspond to the column names.</p>
<p>&nbsp;</p>
<h4>PDO query execution method</h4>
<p>PDO::exec &#8211; PDO::exec method use for INSERT, UPDATE and DELETE statement.<br />
PDO::query -  PDO::exec method use for SELECT statement.<br />
&nbsp;</p>
<h4>Example for mysql database</h4>
<p>CREATE TABLE `books` (<br />
`id` int(11) NOT NULL auto_increment,<br />
`title` varchar(150) NOT NULL,<br />
`author` varchar(150) NOT NULL,<br />
`description` varchar(255) NOT NULL,<br />
`on_sale` tinyint(1) NOT NULL,<br />
PRIMARY KEY  (`id`)<br />
);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (1, &#8216;PHP AJAX&#8217;, &#8216;Andreas&#8217;, &#8216;This is good book for learning AJAX&#8217;, 1);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (2, &#8216;PHP Eclipse &#8216;, &#8216;George&#8217;, &#8216;Nice book&#8217;, 0);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (3, &#8216;PHP Prado&#8217;, &#8216;Junyian&#8217;, &#8216;-&#8217;, 1);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (4, &#8216;PHP Zend Framework&#8217;, &#8216;Ozulian&#8217;, &#8216;great&#8217;, 0);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (5, &#8216;PHP Web Services&#8217;, &#8216;Bobi&#8217;, &#8221;, 0);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (6, &#8216;PHP API&#8217;, &#8216;Hugo&#8217;, &#8221;, 1);</p>
<p>INSERT INTO `books` (`id`, `title`, `author`, `description`, `on_sale`) VALUES (7, &#8216;PHP SEO&#8217;, &#8216;Monteo&#8217;, &#8221;, 1);</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$host</span>;dbname=<span style="color: #006699; font-weight: bold;">$db</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM books&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;failed!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_ASSOC</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will return title from books table using PDO and this code will work for all supported databases.</p>
<h4>Thing to remember:</h4>
<p>PDO uses object-oriented features which is available in PHP 5 (and up) only. So, you must have PHP 5 or newer installed to use PDO for writing scripts that access MySQL.</p>
<p>&nbsp;<br />
Hope this will be helpful for a quick start <img src='http://evolvan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
&nbsp;</p>
<h4>References:</h4>
<p>http://www.php.net/manual/en/pdo.query.php</p>
<p>http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/blog/pdo-database-access/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expressions in MySQL</title>
		<link>http://evolvan.com/blog/regular-expressions-mysql</link>
		<comments>http://evolvan.com/blog/regular-expressions-mysql#comments</comments>
		<pubDate>Sun, 10 Jun 2012 12:24:05 +0000</pubDate>
		<dc:creator>taj</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=384</guid>
		<description><![CDATA[Regular expressions (regex) are known to solve complex comparison problems. When it comes to Sql, numbers of developers don’t even know MySQL supports regular expressions. Let us directly jump to a couple of examples: &#160; SELECT name FROM students WHERE name REGEXP  &#8216;^(A&#124;E&#124;I&#124;O&#124;U)&#8217; Above SQL will retrieve students with name starting with character ‘A’, ‘E’, [...]]]></description>
				<content:encoded><![CDATA[<div style="font-size:1.3em;margin-top:30px">
<a href="http://en.wikipedia.org/wiki/Regular_expression">Regular expressions</a> (regex) are known to solve complex comparison problems. When it comes to Sql, numbers of developers don’t even know <a href="http://dev.mysql.com/doc/refman/5.6/en/regexp.html">MySQL supports regular expressions</a>. Let us directly jump to a couple of examples:<br />
&nbsp;</p>
<p><span style="color: #993300;"><strong>SELECT</strong></span> name <span style="color: #993300;"><strong>FROM</strong></span> students <span style="color: #993300;"><strong>WHERE</strong></span> name <span style="color: #993300;"><strong>REGEXP </strong></span><span style="color: #3366ff;"> &#8216;^(A|E|I|O|U)&#8217;</span></p>
<p>Above SQL will retrieve students with name starting with character ‘A’, ‘E’, ‘I’, ‘O’ or ‘U’</p>
<p>&nbsp;<br />
<span style="color: #993300;"><strong>SELECT</strong></span> name <span style="color: #993300;"><strong>FROM</strong></span> students <span style="color: #993300;"><strong>WHERE</strong></span> hobbies <span style="color: #993300;"><strong>REGEXP</strong></span>  <span style="color: #3366ff;">&#8216;[[:&lt;:]]badminton[[:&gt;:]]&#8217;</span></p>
<p>Above SQL will retrieve students having a word ‘badminton’ in `hobbies`</p>
<p>&nbsp;</p>
<h4>MYSQL METACHARACTERS:</h4>
<ul style="margin:20px 0 0 40px;">
<li>. match any character </li>
<li>? match zero or one</li>
<li>* match zero or more</li>
<li>+ match one or more</li>
<li>^ beginning of line</li>
<li>$ end of line</li>
<li>{n} match n times</li>
<li>{m,n} match m through n times</li>
<li>{n,} match n or more times</li>
<li>[abc] match one of enclosed chars</li>
<li>[^xyz] match any char not enclosed</li>
<li>| separates alternatives</li>
<li>[:class:] match a character class
<ul style="margin-left:40px;">
<li>[:alpha:] for letters</li>
<li>[:space:] for whitespace</li>
<li>[:punct:] for punctuation</li>
<li>[:upper:] for upper case letters</li>
</ul>
</li>
<li>[[:&lt;:]] match beginning of words</li>
<li>[[:&gt;:]] match ending of words</li>
</ul>
<p>&nbsp;</p>
<h4>CAUTION:</h4>
<ol style="margin:20px 0 0 40px;">
<li>REGEXP operator works in bit-wise fashion. It means it may produce unexpected results while being used against multi-byte character set data.</li>
<li>Queries with REGEXP can’t use indexes and may slow down the performance.</li>
<li>MySQL supports <a href="http://en.wikipedia.org/wiki/POSIX">POSIX</a> regular expressions which lack negative lookaheads.</li>
</ol>
<p>&nbsp;</p>
<h4>CONCLUSION:</h4>
<p style="margin:20px 0 0 24px;">While MySQL has extensive regex support and can be a handy and powerful tool, it has some downsides and can affect the SQL performance causing more problems than it can solve. So, if results can be achieved with <a href="http://dev.mysql.com/doc/refman/5.6/en/string-comparison-functions.html#operator_like">LIKE</a> or other string function, REGEXP must be avoided.</p>
</div>
<p>&nbsp;<br />
happy coding&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/blog/regular-expressions-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CO-TROT</title>
		<link>http://evolvan.com/blog/co-trot</link>
		<comments>http://evolvan.com/blog/co-trot#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:25:09 +0000</pubDate>
		<dc:creator>us</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://evolvan.com/?p=325</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://evolvan.com/blog/co-trot/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
