<?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>strictlyPHP &#187; mysql</title>
	<atom:link href="http://www.strictlyphp.com/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.strictlyphp.com/blog</link>
	<description>web development &#38; web analytics</description>
	<lastBuildDate>Tue, 08 Mar 2011 10:47:29 +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>Indexes on multiple columns in MySQL</title>
		<link>http://www.strictlyphp.com/blog/2010/02/11/indexes-on-multiple-columns-in-mysql/</link>
		<comments>http://www.strictlyphp.com/blog/2010/02/11/indexes-on-multiple-columns-in-mysql/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 13:40:17 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=1277</guid>
		<description><![CDATA[When optimizing queries, you don&#8217;t need to be reminded that indexes play an important role. Something to remember though: in real-world examples a multi-column index often outperforms multiple indexes. So it can be worth changing something like: INDEX `index1`(`column1`), INDEX `index2`(`column2`) to INDEX `index1`(`column1`, `column2`) MySQL 5.0 introduced an internal method called &#8220;Index Merge&#8221; which [...]]]></description>
			<content:encoded><![CDATA[<p><em>When optimizing queries, you don&#8217;t need to be reminded that indexes play an important role.</em></p>
<p>Something to remember though: in real-world examples <a href="http://www.mysqlperformanceblog.com/2008/08/22/multiple-column-index-vs-multiple-indexes/" target="_blank">a multi-column index often outperforms multiple indexes</a>.<br />
So it can be worth changing something like:</p>
<pre>INDEX `index1`(`column1`),
INDEX `index2`(`column2`)</pre>
<p>to</p>
<pre>INDEX `index1`(`column1`, `column2`)</pre>
<p>MySQL 5.0 introduced an internal method called &#8220;<a href="http://dev.mysql.com/doc/refman/5.0/en/index-merge-optimization.html" target="_blank">Index Merge</a>&#8221; which merges multiple indexes when querying a table (if applicable) but I haven&#8217;t seen this being used that often. On the contrarry, <strong>MySQL often picks one of the indexes </strong>and in these scenario&#8217;s it is especcialy usefull to have one multi-column index.</p>
<p>As always: use <a href="http://dev.mysql.com/doc/refman/5.0/en/using-explain.html" target="_blank">EXPLAIN</a> to see what can be improved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2010/02/11/indexes-on-multiple-columns-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WampServer development with phpMyAdmin 3</title>
		<link>http://www.strictlyphp.com/blog/2009/02/27/wampserver-development-with-phpmyadmin-3/</link>
		<comments>http://www.strictlyphp.com/blog/2009/02/27/wampserver-development-with-phpmyadmin-3/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 16:55:50 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=776</guid>
		<description><![CDATA[After upgrading your WampServer with the latest phpMyAdmin of the 3 branch, you may not be able to sign in and instead get an &#8220;Access denied&#8221; message while everything was running smooth with phpMyAdmin 2. This is caused by a new security feature in phpMyAdmin 3 which by default does not allow access as root [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-781" style="border-width: 0;float: right;margin: 0 0 10px 10px;background-color: #fff;" title="phpMyAdmin" src="http://www.strictlyphp.com/blog/wp-content/uploads/2009/02/logo.png" alt="phpMyAdmin" width="172" height="100" /></p>
<p><em>After upgrading your WampServer with the latest phpMyAdmin of the 3 branch, you may not be able to sign in and instead get an &#8220;Access denied&#8221; message while everything was running smooth with phpMyAdmin 2.</em></p>
<p>This is caused by a new security feature in phpMyAdmin 3 which by default <strong>does not allow access as root without a password</strong> for the &#8216;config&#8217; authentication type.</p>
<p>I do not have to explain why this was introduced and noone will state it isn&#8217;t a good addition. However, if you are developing on localhost and using the default WampServer set-up, you will not have a MySQL root password set. It has the advantage each of you local projects only require a database name.</p>
<p>If you want to circumvent this while not setting a root password, instead set the &#8216;<strong>AllowNoPasswordRoot</strong>&#8216; setting to true in your config.inc.php:</p>
<pre>$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;</pre>
<p><strong>Update</strong>: since version 3.2.0 (?) a second setting is required:</p>
<pre>$cfg['Servers'][$i]['AllowNoPassword'] = true;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2009/02/27/wampserver-development-with-phpmyadmin-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UTF-8 encoded data in PHP and MySQL</title>
		<link>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/</link>
		<comments>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 21:09:54 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=676</guid>
		<description><![CDATA[Since every developer has probably struggled with data encoding once in their career, a short summary &#8220;how to get your data in and out of a MySQL database with PHP&#8221;: When you create your MySQL database, set the collation to one of the UTF-8 options (e.g.: utf8_general_ci). If you have no rights to create or [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-683" style="float: right;margin: 0 0 10px 10px;" title="unicode" src="http://www.strictlyphp.com/blog/wp-content/uploads/2009/01/unicode.png" alt="unicode" width="100" height="139" /></p>
<p><em>Since every developer has probably struggled with data encoding once in their career, a short summary &#8220;how to get your data in and out of a MySQL database with PHP&#8221;:</em></p>
<ul>
<li>When you create your MySQL database, <strong>set the collation to one of the UTF-8 options</strong> (e.g.: <span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">utf8_general_ci). If you have no rights to create or change your database, do this on the table level.<br />
<em>Note:</em> if you use phpMyAdmin, it&#8217;s good to set your &#8220;session&#8221; encoding to UTF-8 before you sign in (although I believe this is now the default). Otherwise perfectly good data could look weird.<br />
</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Secondly, when you create a database connection in PHP, be sure to <strong>set the character set of your connection to UTF-8</strong> by executing<br />
</span></span></span></p>
<pre><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">SET NAMES 'utf8'</span></span></span></pre>
<p><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">(notice the missing dash). Some extensions/adapters may have a method to do this</span></span></span><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> (e.g. PDO)</span></span></span><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> or allow you to pass it as an option.</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Third, <strong>save your PHP script/file as UTF-8 no-<a href="http://en.wikipedia.org/wiki/Byte-order_mark" target="_blank">BOM</a></strong> (no byte-order mark since UTF-8 does not have byte order issues).</span></span></span></li>
<li><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">Last, but most important &amp; applicable to many more projects: <strong>set the charset of your page through the HTTP header</strong>. e.g.:<br />
</span></span></span></p>
<pre><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable">header('Content-Type: text/html;charset=utf-8');</span></span></span></pre>
<p><span class="nodeLabelBox repTarget"><span class="nodeAttr editGroup"><span class="nodeValue editable"> <em>Note</em>: do not use the &lt;meta&gt; tag (solely) for this.  Only using the meta tag causes most browsers to start re-parsing your content once they notice it&#8217;s UTF-8 instead of their default assumption. This only slows down page loading.</span></span></span></li>
</ul>
<p>This post is certainly not meant to be a Unicode manual but it can be a quick reference when you every wonder why you see those strange characters in your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2009/01/20/utf-8-encoded-data-in-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Language specific tables in MySQL</title>
		<link>http://www.strictlyphp.com/blog/2008/11/13/language-specific-tables-in-mysql/</link>
		<comments>http://www.strictlyphp.com/blog/2008/11/13/language-specific-tables-in-mysql/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 14:23:26 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=321</guid>
		<description><![CDATA[Since a large part of the world doesn&#8217;t care about i18n and L10n, remarkably little articles on best practices are available about these topics. If you live in a multilingual country however, you can&#8217;t build an application without. For a recent project I was looking at a way to avoid language specific tables (it goes [...]]]></description>
			<content:encoded><![CDATA[<p><em>Since a large part of the world doesn&#8217;t care about i18n and L10n, remarkably little articles on best practices are available about these topics.</em></p>
<p><img class="alignnone size-medium wp-image-333" style="border: 1px solid #ccc;margin: 0 10px 10px 0;text-align: left;" src="http://www.strictlyphp.com/blog/wp-content/uploads/2008/11/languages.jpg" alt="" width="180" height="119" /></p>
<p>If you live in a multilingual country however, you can&#8217;t build an application without. For a recent project I was looking at a way to avoid language specific tables (it goes without saying language specific fields are not an option either!).</p>
<p>Since we all like to keep our data as clean as possible, I have created my language specific tables like this example:</p>
<pre>CREATE TABLE IF NOT EXISTS `country` (
  `code` char(2) NOT NULL,
  `language` char(2) NOT NULL default 'en',
  `name` varchar(100) NOT NULL,
  PRIMARY KEY  (`code`,`language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
<p>A sample country table with the ISO code as identifier, a language ISO code and the country name in that specific language. Notice that code and language form the composed primary key. In a multi-table set-up you would probably have a country table and a country_language table. Although this solution looks so much cleaner <strong>it creates a challenge when it comes to querying</strong>.</p>
<p>Imagine you would have these records:</p>
<pre>DE,en,Germany
DE,de,Deutschland
DE,fr,Allemagne
US,en,United States
US,fr,Étas-Unis</pre>
<p>and you want to get a list of countries for a German audience.</p>
<p>Since much <strong>data in these kinds of tables won&#8217;t be translated into all possible languages</strong> (which is the case for German in this example), you will probably want to settle for a default language if German is not available: let&#8217;s say English in this case.</p>
<p>Basically you want to have a result with Deutschland and United States. After some thought, this query is my best bet:</p>
<pre>SELECT IFNULL(language_set.`code`, default_set.`code`) AS 'code',
  IFNULL(language_set.`language`, default_set.`language`) AS 'language',
  IFNULL(language_set.`name`, default_set.`name`) AS 'name'
FROM `country` AS default_set
LEFT OUTER JOIN `country` AS language_set
  ON default_set.`code` = language_set.`code`
  AND language_set.`language` = 'de'
WHERE default_set.`language` = 'en'</pre>
<p>This creates <strong>a set of German data joined by English data if German is not available</strong>. Since MySQL supports sub-queries for some time, you can use this set as a sub-query in any larger query. In my project I&#8217;ve put this default query in each language-based model for re-use in larger queries. For example:</p>
<pre>$sql = "SELECT DISTINCT country.*
  FROM (" . $completeSet . ") AS 'country'
  INNER JOIN other_table ON country.`code` = other_table.`country_code`
  ORDER BY country.`name`";</pre>
<p>This would query all countries that have records in other_table.</p>
<p>Until now, I haven&#8217;t found a situation where this could not be used. I don&#8217;t guarantee that there isn&#8217;t one though. Any improvements are highly appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2008/11/13/language-specific-tables-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL stored procedures with PDO on Windows</title>
		<link>http://www.strictlyphp.com/blog/2008/10/27/mysql-stored-procedures-pdo-windows/</link>
		<comments>http://www.strictlyphp.com/blog/2008/10/27/mysql-stored-procedures-pdo-windows/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 16:00:48 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=276</guid>
		<description><![CDATA[I have mixed feelings when it comes to stored procedures. On one side, they pull away a part of your applications logic which decreases maintainability. While on the other side they tend to perform better and are easily accessible (for instance, by a DBA). Anyway, there are certainly situations were I use them and while [...]]]></description>
			<content:encoded><![CDATA[<p><em>I have mixed feelings when it comes to stored procedures. On one side, they pull away a part of your applications logic which decreases maintainability. While on the other side they tend to perform better and are easily accessible (for instance, by a DBA).</em></p>
<p>Anyway, there are certainly situations were I use them and while doing so on MySQL I bumped into this <a href="http://bugs.php.net/bug.php?id=39759" target="_blank">bug report</a> (and this <a href="http://bugs.php.net/bug.php?id=39858" target="_blank">related one</a>). One stored procedure call did not produce any errors but when I added a second, PDO threw &#8220;General error: 2014 Cannot execute queries while other unbuffered queries are active.&#8221;.</p>
<p>Apparently <strong>using PDO to call multiple MySQL stored procedures on a Windows environment</strong> (e.g. your development WampServer) <strong>causes</strong> a few <strong>errors </strong>(different ones depending on the amount of calls if I&#8217;m correct). After 2 years it should have been fixed mid September &#8217;08 so hopefully the next PHP release will correct this.</p>
<p>In case you ever wondered: this seems to be a reason why the popular e-commerce solution <a href="http://www.magentocommerce.com/" target="_blank">Magento</a> currently requires a linux server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2008/10/27/mysql-stored-procedures-pdo-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uppercase first letter of a string with MySQL</title>
		<link>http://www.strictlyphp.com/blog/2008/08/15/uppercase-first-letter-of-a-string-with-mysql/</link>
		<comments>http://www.strictlyphp.com/blog/2008/08/15/uppercase-first-letter-of-a-string-with-mysql/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 20:14:48 +0000</pubDate>
		<dc:creator>Sam</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.strictlyphp.com/blog/?p=71</guid>
		<description><![CDATA[I just searched for a MySQL clone of the ucfirst(string) PHP function which converts the first letter of a string to a capital, but couldn&#8217;t find one. Just to save you some work &#8211; I used this: UPDATE `table` SET `field` = CONCAT(UPPER(LEFT(`field`, 1)), SUBSTRING(`field`, 2)) and if you want to have all other characters [...]]]></description>
			<content:encoded><![CDATA[<p>I just searched for a MySQL clone of the <a href="http://be.php.net/manual/en/function.ucfirst.php" target="_blank">ucfirst(string) PHP function</a> which converts the first letter of a string to a capital, but couldn&#8217;t find one.<br />
Just to save you some work &#8211; I used this:</p>
<pre>UPDATE `table` SET
`field` = CONCAT(UPPER(LEFT(`field`, 1)), SUBSTRING(`field`, 2))</pre>
<p>and if you want to have all other characters lowercased:</p>
<pre>UPDATE `table` SET
`field` = CONCAT(UPPER(LEFT(`field`, 1)), LOWER(SUBSTRING(`field`, 2)))</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.strictlyphp.com/blog/2008/08/15/uppercase-first-letter-of-a-string-with-mysql/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

