<?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>Graphic Maniacs &#187; MySQL</title>
	<atom:link href="http://graphicmaniacs.com/cat/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://graphicmaniacs.com</link>
	<description></description>
	<lastBuildDate>Wed, 18 Jan 2012 13:08:40 +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 regexp word boundary explained</title>
		<link>http://graphicmaniacs.com/note/mysql-regexp-word-boundary-explained/</link>
		<comments>http://graphicmaniacs.com/note/mysql-regexp-word-boundary-explained/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 07:58:32 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=856</guid>
		<description><![CDATA[The word boundary regexp is something you may need when a list of data is saved in a single column. Example: id numbers 1 2,34,647 2 78,102,342 3 34,78,103 Now our task would be to select IDs where numbers contain &#8220;2&#8243; and &#8220;34&#8243;. One would say that we can do SELECT * FROM mytable WHERE [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-regexp-word-boundary-explained/' addthis:title='MySQL regexp word boundary explained '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>The word boundary regexp is something you may need when a list of data is saved in a single column. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">id   numbers
1    2,34,647
2    78,102,342
3    34,78,103</pre></div></div>

<p>Now our task would be to select IDs where numbers contain &#8220;2&#8243; and &#8220;34&#8243;. One would say that we can do</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SELECT * FROM mytable WHERE numbers LIKE &quot;2&quot; OR numbers LIKE &quot;34&quot;</pre></div></div>

<p>But that won&#8217;t work correctly, because 2 will match 2, 102 and 342, which is something we don&#8217;t need. In this case MySQL word boundary regex comes handy:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SELECT * FROM mytable WHERE numbers REGEXP &quot;[[:&lt;:]]2[[:&gt;:]]&quot; OR numbers REGEXP &quot;[[:&lt;:]]34[[:&gt;:]]&quot;</pre></div></div>

<p>Take a look at <strong>[[:&lt;:]]</strong> and <strong>[[:&gt;:]]</strong>. This is all we need here. The word boundary regex makes sure the match we are looking for is a standalone word, matching without commas and spaces, and making sure the &#8220;2&#8243; word doesn&#8217;t have additional letters/numbers on left/right side. This is pretty awesome and saves our day!</p>
<h4>This page can be found by searching for:</h4><div class='search-terms'><span>mysql regex json</span><span>mysql regex</span><span>mysql regexp</span><span>mysql regexp search explained</span><span>mysql replace word boundary</span><span>mysql where like word boundary</span><span>php mysql regexp word boundary</span><span>word boundary</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-regexp-word-boundary-explained/' addthis:title='MySQL regexp word boundary explained '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/mysql-regexp-word-boundary-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing UTF-8 characters which are stored in Latin1 or other encoding</title>
		<link>http://graphicmaniacs.com/note/fixing-utf-8-characters-which-are-stored-in-latin1-or-other-encoding/</link>
		<comments>http://graphicmaniacs.com/note/fixing-utf-8-characters-which-are-stored-in-latin1-or-other-encoding/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 15:57:33 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=480</guid>
		<description><![CDATA[I noticed this issue while working on US-based servers. There&#8217;s usually ISO-8859-1 encoding in MySQL by default, so if you accidentally didn&#8217;t change that and worked with russian or other than english characters, the data may be presented as: ÐšÐ¾Ð»Ð»ÐµÐºÑ†Ð¸Ñ ÑÑ‚Ð¾ÐºÐ¾Ð²Ñ‹Ñ… Ñ„Ð¾Ñ‚Ð¾Ð³Ñ€Ð°Ñ„Ð¸Ð¹ Which in my case was converted upon output to Коллекция стоковых фотографий This [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/fixing-utf-8-characters-which-are-stored-in-latin1-or-other-encoding/' addthis:title='Fixing UTF-8 characters which are stored in Latin1 or other encoding '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I noticed this issue while working on US-based servers. There&#8217;s usually ISO-8859-1 encoding in MySQL by default, so if you accidentally didn&#8217;t change that and worked with russian or other than english characters, the data may be presented as:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ÐšÐ¾Ð»Ð»ÐµÐºÑ†Ð¸Ñ ÑÑ‚Ð¾ÐºÐ¾Ð²Ñ‹Ñ… Ñ„Ð¾Ñ‚Ð¾Ð³Ñ€Ð°Ñ„Ð¸Ð¹</pre></div></div>

<p>Which in my case was converted upon output to</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Коллекция стоковых фотографий</pre></div></div>

<p>This is ok if you need to just display it, but if you need to perform search or sort or any other mysql operations, you will FAIL. The fix for this is to convert the table column to binary, then back to UTF8. This way the data remains untouched but in proper encoding.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> NAMES latin1; 
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> links <span style="color: #993333; font-weight: bold;">MODIFY</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> link_title TEXT <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> latin1; 
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> links <span style="color: #993333; font-weight: bold;">MODIFY</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> link_title <span style="color: #993333; font-weight: bold;">BLOB</span>; 
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> links <span style="color: #993333; font-weight: bold;">MODIFY</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> link_title TEXT <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8; 
<span style="color: #993333; font-weight: bold;">SET</span> NAMES utf8;</pre></div></div>

<p>After that, don&#8217;t forget to always &#8220;SET NAMES utf8&#8243; in your php application if you don&#8217;t have access to php.ini. It fixed my issues like magic and i continued working with same data without any loss.</p>
<h4>This page can be found by searching for:</h4><div class='search-terms'><span>unscrambling utf8</span><span>utf-8 ñ</span><span>utf8 ñ</span><span>cs cart seo name UTF8 edit</span><span>cs-cart encoding</span><span>google chrome change character encoding latin1</span><span>chrome encoding latin1</span><span>php translate ñ from latin1 to utf8</span><span>setting cs cart to utf-8</span><span>utf-8 character set ñ</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/fixing-utf-8-characters-which-are-stored-in-latin1-or-other-encoding/' addthis:title='Fixing UTF-8 characters which are stored in Latin1 or other encoding '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/fixing-utf-8-characters-which-are-stored-in-latin1-or-other-encoding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL query to change character set, connection encoding, collation etc.</title>
		<link>http://graphicmaniacs.com/note/mysql-query-to-change-character-set-connection-encoding-collation-etc/</link>
		<comments>http://graphicmaniacs.com/note/mysql-query-to-change-character-set-connection-encoding-collation-etc/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 01:21:01 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=461</guid>
		<description><![CDATA[This may become handy in case your database and website encoding is a bit different from what the server thought would be perfect. Simply run this query after successful mysql_connect: mysql_query&#40;&#34;SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'&#34;&#41;; Don&#8217;t forget to adjust the encoding names according to [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-query-to-change-character-set-connection-encoding-collation-etc/' addthis:title='MySQL query to change character set, connection encoding, collation etc. '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>This may become handy in case your database and website encoding is a bit different from what the server thought would be perfect.<br />
Simply run this query after successful mysql_connect:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Don&#8217;t forget to adjust the encoding names according to your configs (because not every website and database uses utf8).</p>
<p>Additionally, it may be possible to fix your encoding bugs with a simple single query (works in every 3rd situation):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_set_charset</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>This page can be found by searching for:</h4><div class='search-terms'><span>mysql query charset</span><span>mysql query encoding</span><span>MYSQL query character set</span><span>mysql query to change collation</span><span>mysql set collation in query</span><span>mysql charset query</span><span>mysql encode query</span><span>mysql encoding query</span><span>mysql query encode</span><span>mysql collation query</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-query-to-change-character-set-connection-encoding-collation-etc/' addthis:title='MySQL query to change character set, connection encoding, collation etc. '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/mysql-query-to-change-character-set-connection-encoding-collation-etc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Performing multiple MySQL queries in PHP</title>
		<link>http://graphicmaniacs.com/note/performing-multiple-mysql-queries-in-php/</link>
		<comments>http://graphicmaniacs.com/note/performing-multiple-mysql-queries-in-php/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 01:14:03 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=455</guid>
		<description><![CDATA[Yes, i mean multiple. Usually this is used when you have for ex. big export file from phpMyAdmin with multiple CREATE TABLEs, INSERTs etc. I came across the solution provided with some website i can&#8217;t remember Basically, split the queries at the point where there are semicolons and query each split. $sql = &#34; CREATE [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/performing-multiple-mysql-queries-in-php/' addthis:title='Performing multiple MySQL queries in PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Yes, i mean multiple. Usually this is used when you have for ex. big export file from phpMyAdmin with multiple CREATE TABLEs, INSERTs etc.<br />
I came across the solution provided with some website i can&#8217;t remember<br />
Basically, split the queries at the point where there are semicolons and query each split.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; 
CREATE TABLE IF NOT EXISTS `zcta` ( `zip` char(5) NOT NULL, `city` varchar(64) default NULL, PRIMARY KEY  (`zip`)) ENGINE=MyISAM DEFAULT CHARSET=latin1; 
INSERT INTO `zcta` (`zip`, `city`) VALUES
('00211', 'Portsmouth'),
('00212', 'Portsmouth');
&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Something like that, now we split the string where the ; is and make sure it isn&#8217;t the value inside the query (this weird regexp does it all)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$queries</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/;+(?=([^'|^<span style="color: #000099; font-weight: bold;">\\</span>\']*['|<span style="color: #000099; font-weight: bold;">\\</span>\'][^'|^<span style="color: #000099; font-weight: bold;">\\</span>\']*['|<span style="color: #000099; font-weight: bold;">\\</span>\'])*[^'|^<span style="color: #000099; font-weight: bold;">\\</span>\']*[^'|^<span style="color: #000099; font-weight: bold;">\\</span>\']$)/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<h4>This page can be found by searching for:</h4><div class='search-terms'><span>multiple mysql queries php</span><span>multi query mysql php</span><span>multiple mysql query php</span><span>split multiple queries php</span><span>multi query php</span><span>php mysql multiple queries</span><span>query mysql free grafic php</span><span>split multi query mysql</span><span>query mysql explode php</span><span>php set multi query mysql</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/performing-multiple-mysql-queries-in-php/' addthis:title='Performing multiple MySQL queries in PHP '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/performing-multiple-mysql-queries-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL REPLACE. Replacing content in WordPress</title>
		<link>http://graphicmaniacs.com/note/mysql-replace-replacing-content-in-wordpress/</link>
		<comments>http://graphicmaniacs.com/note/mysql-replace-replacing-content-in-wordpress/#comments</comments>
		<pubDate>Wed, 19 May 2010 20:37:54 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://graphicmaniacs.com/?p=353</guid>
		<description><![CDATA[Sometimes, when you make some changes, like new domain url or fixing tags (for ex. replacing &#60;br&#62; to &#60;br /&#62;) you need to run a simple query and not do crazy PHP magic. Here is the quick example of how you use the MySQL REPLACE function. To replace old url with new url in WordPress [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-replace-replacing-content-in-wordpress/' addthis:title='MySQL REPLACE. Replacing content in WordPress '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Sometimes, when you make some changes, like new domain url or fixing tags (for ex. replacing &lt;br&gt; to &lt;br /&gt;) you need to run a simple query and not do crazy PHP magic. Here is the quick example of how you use the MySQL REPLACE function. </p>
<p>To replace old url with new url in WordPress posts content:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> wp_posts <span style="color: #993333; font-weight: bold;">SET</span> post_content <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>post_content<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;http://oldurl.com&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;http://newurl.com&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>To replace all &lt;code&gt; tags with &lt;pre&gt; run these 2 queries. Note that i put <strong>&lt;code</strong>, that&#8217;s in case there are some attributes in the tag</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> wp_posts <span style="color: #993333; font-weight: bold;">SET</span> post_content <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>post_content<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;&lt;code&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;&lt;pre&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> wp_posts <span style="color: #993333; font-weight: bold;">SET</span> post_content <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>post_content<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;&lt;/code&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;&lt;/pre&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h4>This page can be found by searching for:</h4><div class='search-terms'><span>wp_posts mysql replace</span><span>mysql replace for wordpress</span><span>post_content wordpress</span><span>wordpress post_content example</span><span>wordpress replace post_content</span></div><br /><br /><div class="addthis_toolbox addthis_default_style " addthis:url='http://graphicmaniacs.com/note/mysql-replace-replacing-content-in-wordpress/' addthis:title='MySQL REPLACE. Replacing content in WordPress '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://graphicmaniacs.com/note/mysql-replace-replacing-content-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

