<?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>Orite Blog &#187; MySQL</title>
	<atom:link href="http://blog.orite.com.au/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.orite.com.au</link>
	<description>Think Work Learn Share</description>
	<lastBuildDate>Fri, 24 Jul 2009 00:08:02 +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>mwbModelCommand, Yii Framework and MySQL Workbench</title>
		<link>http://blog.orite.com.au/web_development/2009-02-06/mwbmodelcommand-yii-framework-and-mysql-workbench/</link>
		<comments>http://blog.orite.com.au/web_development/2009-02-06/mwbmodelcommand-yii-framework-and-mysql-workbench/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 13:26:32 +0000</pubDate>
		<dc:creator>Frank Liu</dc:creator>
				<category><![CDATA[Open Source Releases]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Yii Framework]]></category>

		<guid isPermaLink="false">http://blog.orite.com.au/?p=61</guid>
		<description><![CDATA[In the past few weeks we have been exploring with Yii Framework, and two of us have started porting some of our project to Yii Framework. One of the first few things that caught our attention is the CActiveRecord model classes, which require relational rules to describe relationships among database tables. We are glad that [...]]]></description>
			<content:encoded><![CDATA[<p>In the past few weeks we have been exploring with <a title="Yii Framework" href="http://www.yiiframework.com" target="_blank">Yii Framework</a>, and two of us have started porting some of our project to Yii Framework. One of the first few things that caught our attention is the <a title="Yii Framework CActiveRecord" href="http://www.yiiframework.com/doc/api/CActiveRecord" target="_blank">CActiveRecord</a> model classes, which require relational rules to describe relationships among database tables. We are glad that Yiic can help to create project scaffolds and create controller, model and CRUD, however it's not very practical to manually add all the relationship if your project has over 10 tables.</p>

<p>Our normal practice prefers to design database with relational diagram, so it not only sets out the table schemas but also visually demonstrates the relationship of database tables.  However in this fast changing world, without the right tool most the relational diagram tends to out of sync with real production database. For most the of our project, we create ERD and generate database from the diagram in the design phase and later on in the development phase, most the developer choose to update the schema on the table directly, since that's quick, and most of them don't have the habit to update the ERD with relavant changes. You will feel lucky if your database design tool comes with reverse engineering, which can help you syn with your database at a later point still, otherwise you'll be purely rely on your bare eye and hand to syn among database table your model classes and the ERD.</p>

<p>So I believe when it comes to database design it should always be diagram driven, therefore if there's any changes need to be made, always update the digram first and carry on to your physical table and model class. Although we are still looking for good database migration tools to manage schema diffs. We have written a little script to help Yii Framework to work with <a title="MySQL Workbench" href="http://dev.mysql.com/workbench/" target="_blank">MySQL Workbench</a> (which we use to model MySQL databases), the purpose of the script is to batch create model classes for Yii Framework (although Yiic can generate models one by one, we want it happen at once and for all), and with the help of mwb file it can create the relational rules for the models, so there's no manual translation needed while you creating the models. Since it's a Yii shell command, we have named it 'mwbModelCommand'.</p>

<p>It's available for download at this <a title="mwbModelCommand" href="http://www.yiiframework.com/extension/mwbmodelcommand/" target="_blank">Yii Extensions page</a>, or <a title="Yii Framework mwbModelCommand" href="../wp-content/uploads/2009/02/mwbmodelcommand_r2402.zip">Yii Framework mwbModelCommand</a> (direct link)</p>

<p>Hope this script will save your time on relational model creation, if anyone have issues or suggestions mwbModelCommand please feel free to post back.</p>

<p>Wish List (Todo),<br />
A tool (set) to stream line the database migration, so it would not only creates the models, but may also update (revert) models as well as database table schema at once, and data safe if possible. Please advice if you know something good out there.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.orite.com.au/web_development/2009-02-06/mwbmodelcommand-yii-framework-and-mysql-workbench/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Converting MySQL Database to UTF-8</title>
		<link>http://blog.orite.com.au/web_development/2009-01-19/converting-mysql-table-to-utf-8/</link>
		<comments>http://blog.orite.com.au/web_development/2009-01-19/converting-mysql-table-to-utf-8/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 21:55:22 +0000</pubDate>
		<dc:creator>Frank Liu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.orite.com.au/?p=33</guid>
		<description><![CDATA[When we were building a WordPress website for a Chinese community we found even the configuration in WordPress defined default charset as 'UTF-8', becase the datbase tables/fields are by default not in 'utf8_unicode_ci', it won't allow users to post in Chinese the characters all come up as ? marks. So we decide to alter all [...]]]></description>
			<content:encoded><![CDATA[<p>When we were building a WordPress website for a Chinese community we found even the configuration in WordPress defined default charset as 'UTF-8', becase the datbase tables/fields are by default not in 'utf8_unicode_ci', it won't allow users to post in Chinese the characters all come up as ? marks.</p>
<p>So we decide to alter all the tables and fields for WordPress to UTF-8, which would fix the problem. However it's not easy to change all the fields one by one from one charset and collation to another. Then we have written the following php script to help converting the tables and all text fields to UTF-8.</p>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.orite.com.au/wp-content/plugins/wp-codebox/wp-codebox.php?p=33&amp;download=mysql_utf8.php">mysql_utf8.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p332"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" id="p33code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//mysql database name</span>
<span style="color: #000088;">$db_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;my_test&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//db connection</span>
<span style="color: #000088;">$dc</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/mysql_select_db"><span style="color: #990000;">mysql_select_db</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//set database charset and collation</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ALTER DATABASE `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$db_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci&quot;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//set tables charset and collation</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SHOW TABLES&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tables</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</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> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ALTER TABLE `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;`  DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci&quot;</span><span style="color: #339933;">;</span>
	<a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tables</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//set table rows charset and collation</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tables</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tab</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SHOW FULL COLUMNS FROM `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$tab</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;`&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</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> <a href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</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: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Collation'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Collation'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'utf8_unicode_ci'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$nu</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Null'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;YES&quot;</span><span style="color: #009900;">&#41;</span>? <span style="color: #0000ff;">&quot;NULL&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;NOT NULL&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$df</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Default'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;DEFAULT '&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/addslashes"><span style="color: #990000;">addslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Default'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ALTER TABLE `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$tab</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` CHANGE `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` `&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;` &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; CHARACTER SET utf8 COLLATE utf8_unicode_ci &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$nu</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$df</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>To set the MySQL default charset and collation to UTF-8, so the tables created later without any charset or collation specification would be default to UTF-8, please add these two lines to your my.cnf file under [mysqld],</p>
<pre>
character-set-server=utf8
default-collation=utf8_unicode_ci
</pre>]]></content:encoded>
			<wfw:commentRss>http://blog.orite.com.au/web_development/2009-01-19/converting-mysql-table-to-utf-8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XAMPP 1.7.0 for Windows Problem</title>
		<link>http://blog.orite.com.au/web_development/2009-01-16/xampp-170-for-windows-problem/</link>
		<comments>http://blog.orite.com.au/web_development/2009-01-16/xampp-170-for-windows-problem/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 03:11:07 +0000</pubDate>
		<dc:creator>Frank Liu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XAMPP]]></category>

		<guid isPermaLink="false">http://blog.orite.com/?p=7</guid>
		<description><![CDATA[We recently updated our XAMPP on developers work stations to 1.7.0, since it incorporates the latest MySQL 5.1 and PHP 5.2.8 releases. However we dicovered an issue with the mysql libraries which prevents PDO from running properly. Come with the package there are two versions of mysql libraries, if you check xampp/php and xampp/apache/bin you [...]]]></description>
			<content:encoded><![CDATA[We recently updated our <a href="http://www.apachefriends.org/en/xampp-windows.html">XAMPP</a> on developers work stations to 1.7.0, since it incorporates the latest MySQL 5.1 and PHP 5.2.8 releases.

However we dicovered an issue with the mysql libraries which prevents PDO from running properly.

Come with the package there are two versions of mysql libraries, if you check xampp/php and xampp/apache/bin you will find one is named lib<span style="font-family: Helvetica,Arial,sans-serif;">mysql_5.0.51a on the files, the other is just </span>lib<span style="font-family: Helvetica,Arial,sans-serif;">mysql.dll, all we did to fix the problem is replacing the library files with the 5.051a files in the directories mentioned before. Also in </span><span style="font-family: Helvetica,Arial,sans-serif;">xampp/php/ext there're </span><span style="font-family: Helvetica,Arial,sans-serif;">php_mysqli.dll and </span><span style="font-family: Helvetica,Arial,sans-serif;">php_mysql.dll needs replacing too.</span>

<span style="font-family: Helvetica,Arial,sans-serif;">Please make sure you stop Apache before replacing file under </span>xampp/apache/bin

This should fix the problem with PDO.]]></content:encoded>
			<wfw:commentRss>http://blog.orite.com.au/web_development/2009-01-16/xampp-170-for-windows-problem/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

