<?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>cakebaker &#187; mysql</title>
	<atom:link href="http://cakebaker.42dh.com/tags/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:29: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>Generating a Rails project configured to use MySQL</title>
		<link>http://cakebaker.42dh.com/2009/03/13/generating-a-rails-project-configured-to-use-mysql/</link>
		<comments>http://cakebaker.42dh.com/2009/03/13/generating-a-rails-project-configured-to-use-mysql/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 16:55:23 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1137</guid>
		<description><![CDATA[A little trap I blundered into each time I generated a Rails project with $ rails example // Rails 2.x $ rails new example // Rails 3.x is that by default a generated project is configured to use a SQLite database. And so the configuration file for the databases looks as shown below (I omit [...]]]></description>
			<content:encoded><![CDATA[<p>A little trap I blundered into each time I generated a Rails project with</p>
<pre>
<code>$ rails example // Rails 2.x
$ rails new example // Rails 3.x</code>
</pre>
<p>is that by default a generated project is configured to use a <a href="http://sqlite.org/">SQLite</a> database. And so the configuration file for the databases looks as shown below (I omit the configurations for the &#8220;test&#8221; and &#8220;production&#8221; environments, as they are almost identical):</p>
<pre>
<code># example/config/database.yml
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000</code>
</pre>
<p>This leads, of course, to an error as soon as you try to access the database while there is no such driver installed ;-)</p>
<p>To avoid this small problem, you have to specify the database type when using the &#8220;rails&#8221; command:</p>
<pre>
<code>$ rails -d mysql example // Rails 2.x
$ rails new example -d mysql // Rails 3.x</code>
</pre>
<p>This command then generates the following database.yml:</p>
<pre>
<code># example/config/database.yml
development:
  adapter: mysql  # Rails 3.x uses the mysql2 adapter
  encoding: utf8
  database: example_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock</code>
</pre>
<p>Happy Rails baking!</p>
<p>Update 2009-03-23: An alternative approach in Rails 2.x is to define the variable RAILS_DEFAULT_DATABASE with:</p>
<pre>
<code>$ export RAILS_DEFAULT_DATABASE=mysql</code>
</pre>
<p>Update 2011-02-20: Adapted for Rails3</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2009/03/13/generating-a-rails-project-configured-to-use-mysql/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Order by field</title>
		<link>http://cakebaker.42dh.com/2008/06/10/order-by-field/</link>
		<comments>http://cakebaker.42dh.com/2008/06/10/order-by-field/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 17:09:33 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=613</guid>
		<description><![CDATA[Yesterday, Tarique Sani mentioned in a thread in the CakePHP Group &#8220;order by field&#8221;. I know &#8220;order by&#8221;, but I never heard about &#8220;order by field&#8221; (which seems to be MySQL-specific). Ok, let&#8217;s do some examples to learn more about it. We will use the following countries table: [1] =&#62; USA [2] =&#62; Germany [3] [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, <a href="http://www.sanisoft.com/blog/author/tariquesani/">Tarique Sani</a> mentioned in a <a href="http://groups.google.com/group/cake-php/browse_thread/thread/dfdebc408aac8bc0/e99c0260204a8ec8">thread</a> in the CakePHP Group &#8220;order by field&#8221;. I know &#8220;order by&#8221;, but I never heard about &#8220;order by field&#8221; (which seems to be MySQL-specific). </p>
<p>Ok, let&#8217;s do some examples to learn more about it. We will use the following countries table:</p>
<pre>
[1] =&gt; USA
[2] =&gt; Germany
[3] =&gt; Russia
[4] =&gt; Austria
[5] =&gt; China
[6] =&gt; Switzerland
</pre>
<p>Now, we don&#8217;t want to sort them by the id, but by some &#8220;strange&#8221; order: Austria, USA, China, Russia, Switzerland, Germany. For this purpose we can use &#8220;order by field&#8221;: the first parameter is the column name and all following parameters are values of the respective column. In CakePHP it is done in the following way:</p>
<pre>
$this-&gt;Country-&gt;find('list', array('order' =&gt; array('FIELD(Country.id, 4, 1, 5, 3, 6, 2)')));
</pre>
<p>And we get the expected result:</p>
<pre>
[4] =&gt; Austria
[1] =&gt; USA
[5] =&gt; China
[3] =&gt; Russia
[6] =&gt; Switzerland
[2] =&gt; Germany
</pre>
<p>Probably more common is the scenario that you want to have certain values at the top of a list, and the other values of the list should be ordered alphabetically. If we want the German-speaking countries at the top of the list we would do:</p>
<pre>
$this-&gt;Country-&gt;find('list', array('order' =&gt; array('FIELD(Country.id, 2, 4, 6)', 'Country.name')));

or 

$this-&gt;Country-&gt;find('list', array('order' =&gt; array('FIELD(Country.name, "Germany", "Austria", "Switzerland")', 'Country.name')));
</pre>
<p>Unfortunately, this doesn&#8217;t return the expected result, the records which should be at the top are at the bottom:</p>
<pre>
[5] =&gt; China
[3] =&gt; Russia
[1] =&gt; USA
[2] =&gt; Germany
[4] =&gt; Austria
[6] =&gt; Switzerland
</pre>
<p>We can solve this &#8220;problem&#8221; by using the &#8220;DESC&#8221; keyword and changing the order of the provided values:</p>
<pre>
$this-&gt;Country-&gt;find('list', array('order' =&gt; array('FIELD(Country.id, 6, 4, 2) DESC', 'Country.name')));

or

$this-&gt;Country-&gt;find('list', array('order' =&gt; array('FIELD(Country.name, "Switzerland", "Austria", "Germany") DESC', 'Country.name')))
</pre>
<p>With those changes we get the expected result:</p>
<pre>
[2] =&gt; Germany
[4] =&gt; Austria
[6] =&gt; Switzerland
[5] =&gt; China
[3] =&gt; Russia
[1] =&gt; USA
</pre>
<p>Thanks to Tarique for mentioning &#8220;order by field&#8221; and to <a href="http://www.gigapromoters.com/blog/">Abhimanyu Grover</a> for asking the original question.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/06/10/order-by-field/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Text datatypes in MySQL</title>
		<link>http://cakebaker.42dh.com/2006/12/03/text-datatypes-in-mysql/</link>
		<comments>http://cakebaker.42dh.com/2006/12/03/text-datatypes-in-mysql/#comments</comments>
		<pubDate>Sun, 03 Dec 2006 10:34:57 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2006/12/03/text-datatypes-in-mysql/</guid>
		<description><![CDATA[Up to now I assumed that the size of text you can store in a field with data type TEXT is almost &#8220;infinite&#8221;. But that is not true. TEXT does only allow 64 kB of data. That&#8217;s more often than not enough. But if you want to store more data you have to use MEDIUMTEXT [...]]]></description>
			<content:encoded><![CDATA[<p>Up to now I assumed that the size of text you can store in a field with data type TEXT is almost &#8220;infinite&#8221;. But that is not true. TEXT does only allow 64 kB of data. That&#8217;s more often than not enough. But if you want to store more data you have to use MEDIUMTEXT or LONGTEXT, which allows you to store 16 MB resp. 4 GB of data. See also <a href="http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html">http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/12/03/text-datatypes-in-mysql/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Selecting data in a specific date range</title>
		<link>http://cakebaker.42dh.com/2006/08/25/selecting-data-in-a-specific-date-range/</link>
		<comments>http://cakebaker.42dh.com/2006/08/25/selecting-data-in-a-specific-date-range/#comments</comments>
		<pubDate>Fri, 25 Aug 2006 09:16:37 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=251</guid>
		<description><![CDATA[Sometimes, you have to return all objects created in a specific date range, e.g. you want to return all posts created in the last thirty days. Thanks to the nice functions for date operations provided by MySQL this task is simple: $this-&#62;Post-&#62;findAll( 'WHERE Post.created &#62;= DATE_SUB(CURDATE(), INTERVAL 30 DAY)');]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you have to return all objects created in a specific date range, e.g. you want to return all posts created in the last thirty days. Thanks to the nice functions for date operations provided by MySQL this task is simple:</p>
<pre>
$this-&gt;Post-&gt;findAll(
    'WHERE Post.created &gt;= DATE_SUB(CURDATE(), INTERVAL 30 DAY)');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/08/25/selecting-data-in-a-specific-date-range/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using UTF-8 as encoding for the database connection</title>
		<link>http://cakebaker.42dh.com/2006/04/16/using-utf-8-as-encoding-for-the-database-connection/</link>
		<comments>http://cakebaker.42dh.com/2006/04/16/using-utf-8-as-encoding-for-the-database-connection/#comments</comments>
		<pubDate>Sun, 16 Apr 2006 08:28:10 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=167</guid>
		<description><![CDATA[I already wrote about this topic some time ago. In that post I described an approach using the configuration file of MySQL, and mentioned casually that you could execute &#8220;SET NAMES utf8&#8243; if you do not have access to the MySQL configuration file. But I did not show a solution for that case&#8230; Well, today [...]]]></description>
			<content:encoded><![CDATA[<p>I already wrote about this topic some time ago. In that <a href="http://cakebaker.wordpress.com/2006/01/16/trouble-with-utf-8/">post</a> I described an approach using the configuration file of MySQL, and mentioned casually that you could execute &#8220;SET NAMES utf8&#8243; if you do not have access to the MySQL configuration file. But I did not show a solution for that case&#8230;</p>
<p>Well, today I saw a solution, presented by nate in a <a href="http://groups.google.com/group/cake-php/browse_thread/thread/7fab97f558245a3b/ffcea44b2bc8c73f#ffcea44b2bc8c73f">post</a> in the google group:</p>
<pre>
// app/app_model.php
class AppModel extends Model
{
    function __construct()
    {
        parent::__construct();
        $this-&gt;execute("Set NAMES 'UTF8'");
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/04/16/using-utf-8-as-encoding-for-the-database-connection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oh my blob!</title>
		<link>http://cakebaker.42dh.com/2006/03/30/oh-my-blob/</link>
		<comments>http://cakebaker.42dh.com/2006/03/30/oh-my-blob/#comments</comments>
		<pubDate>Thu, 30 Mar 2006 15:25:18 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=155</guid>
		<description><![CDATA[I never used blobs before with MySQL, and so I had to learn painful that there are several types of blobs available in MySQL: TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB. And that is the way I had to learn it: In my app the user can upload files, and these files are stored in the database. [...]]]></description>
			<content:encoded><![CDATA[<p>I never used blobs before with MySQL, and so I had to learn painful that there are several types of blobs available in MySQL: TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB. </p>
<p>And that is the way I had to learn it: In my app the user can upload files, and these files are stored in the database. Everything worked fine with small files. But for some reason it didn&#8217;t work with larger files. If I tried to download the uploaded files, the download was discontinued after a short time period. &#8220;Probably a timeout problem&#8221;, I thought. And so I searched in this area for the cause of the problem. Without result. By accident I landed on the page <a href="http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html">&#8220;Data Type Storage Requirements&#8221;</a>, and I got the &#8220;Aha&#8221; effect. I used the wrong data type: &#8220;BLOB&#8221; supports only data up to 64kb&#8230; </p>
<p>Another learning from this episode is that the cause of a problem is sometimes not there where you are looking for&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/03/30/oh-my-blob/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The thing with the euro sign</title>
		<link>http://cakebaker.42dh.com/2006/01/31/the-thing-with-the-euro-sign/</link>
		<comments>http://cakebaker.42dh.com/2006/01/31/the-thing-with-the-euro-sign/#comments</comments>
		<pubDate>Tue, 31 Jan 2006 09:13:11 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[ant]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=87</guid>
		<description><![CDATA[Yesterday, Kabuto asked in the IRC whether someone is using UTF-8 for the MySQL databases and if they experienced some problems with the euro sign. Yes, I use UTF-8 and I also store the euro sign in my database, and I assumed it works for me. But that was an illusion, the euro sign was [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, Kabuto asked in the IRC whether someone is using UTF-8 for the MySQL databases and if they experienced some problems with the euro sign. Yes, I use UTF-8 and I also store the euro sign in my database, and I assumed it works for me. But that was an illusion, the euro sign was shown as a question mark as I did a query. A sign of an encoding problem&#8230; </p>
<p>Since it worked when I entered the euro sign in my application, the problem had to be in my sql scripts or in my <a href="http://ant.apache.org">ant</a> script I use to execute the sql scripts. The sql scripts were ok, as they worked when executed via <a href="http://dev.mysql.com/downloads/query-browser/1.1.html">MySQL Query Browser</a>. So the problem had to be in my ant script. But what was the cause of the problem? After searching for a long time I found the problem: I have to specify the encoding in the URL used by <a href="http://java.sun.com/products/jdbc/">JDBC</a>. Instead of</p>
<pre>
jdbc:mysql://localhost/mydb
</pre>
<p>I have to use </p>
<pre>
jdbc:mysql://localhost/mydb?characterEncoding=UTF-8
</pre>
<p>Oh, I really love this entire encoding stuff ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/01/31/the-thing-with-the-euro-sign/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Trouble with utf-8</title>
		<link>http://cakebaker.42dh.com/2006/01/16/trouble-with-utf-8/</link>
		<comments>http://cakebaker.42dh.com/2006/01/16/trouble-with-utf-8/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 09:00:16 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=61</guid>
		<description><![CDATA[Yesterday, I had some trouble with utf-8. The character set of my tables is utf-8, and I use utf-8 as encoding for my pages, too. No problem, you would think (and it was no problem up to now). But yesterday, I noticed that special characters like öüä are not displayed correctly. I do not know [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I had some trouble with utf-8. The character set of my tables is utf-8, and I use utf-8 as encoding for my pages, too. No problem, you would think (and it was no problem up to now). But yesterday, I noticed that special characters like öüä are not displayed correctly. I do not know if the problem was caused by the latest version of CakePHP, or if the cause was the upgrade to <a href="http://www.mysql.org">MySQL 5.0</a>. Anyway, I could fix it. I had to add the following line to my /etc/mysql/my.cnf file, the configuration file for MySQL:</p>
<pre>
[mysqld]
init-connect = 'SET NAMES utf8'
</pre>
<p>If you do not have access to this file, you can alternatively execute the statement &#8220;SET NAMES utf8&#8243; before you do any sql queries (I have not tested this approach).</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/01/16/trouble-with-utf-8/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A lot of changes in trunk</title>
		<link>http://cakebaker.42dh.com/2006/01/12/a-lot-of-changes-in-trunk/</link>
		<comments>http://cakebaker.42dh.com/2006/01/12/a-lot-of-changes-in-trunk/#comments</comments>
		<pubDate>Thu, 12 Jan 2006 08:36:24 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[acl]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=51</guid>
		<description><![CDATA[Yesterday, a lot of changes have been made to trunk. Here the changes I noticed: there is a new constant called CAKE_SESSION_STRING in core.php app/controllers/components/db_acl.sql has been removed (it is the one I used for my unsuccessful dbAcl experiments *g*) AjaxHelper::linkToRemote() is now deprecated, it is replaced by AjaxHelper::link() dbAcl has been updated, so it [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, a lot of changes have been made to trunk. Here the changes I noticed:</p>
<ul>
<li>
there is a new constant called CAKE_SESSION_STRING in core.php
</li>
<li>
app/controllers/components/db_acl.sql has been removed (it is the one I used for my unsuccessful dbAcl experiments *g*)
</li>
<li>
AjaxHelper::linkToRemote() is now deprecated, it is replaced by AjaxHelper::link()
</li>
<li>
dbAcl has been updated, so it is time for a new dbAcl experiment ;-)
</li>
<li>
there are some new convenience methods: up() for strtoupper(), low() for strtolower(), and r() for str_replace()
</li>
<li>
transaction support for <a href="http://www.mysql.org">MySQL</a>
</li>
<li>
a lot of changes for the <a href="http://www.postgresql.org">PostgreSQL</a> driver
</li>
</ul>
<p>So, it is time to test if my application still works with this update :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/01/12/a-lot-of-changes-in-trunk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

