Message from discussion
The MySQL UTF8 Issue
Received: by 10.11.53.59 with SMTP id b59mr1190495cwa;
Mon, 10 Apr 2006 07:29:07 -0700 (PDT)
Received: from 218.14.36.191 by i39g2000cwa.googlegroups.com with HTTP;
Mon, 10 Apr 2006 14:29:07 +0000 (UTC)
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
To: "Cake PHP" <cake-php@googlegroups.com>
Subject: The MySQL UTF8 Issue
Date: Mon, 10 Apr 2006 07:29:07 -0700
Message-ID: <1144679347.235916.327130@i39g2000cwa.googlegroups.com>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe)
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
I use mysql5 and utf8 table to store Chinese data. Everything
insert into the utf8 tables though cake can be fetch out by cake fine.
But when I use other database tools (such as MySQL Query Browser) to
query the data which insert by cake will got unreadable characters. I'm
so confuse on it, and serach on the internet. I think there is
something wrong with the mysql connections setting in cake.
In my controller I query the MySQL connection setting by do this
...
$msg = $this->MyModel->findBySql("Show VARIABLES LIKE
'%CHARACTER_SET%';");
// Then set the result varable $msg to display in views
$this->set('msg',$msg);
....
In view:
...
debug($msg);
...
Then I got this result:
Array
(
[0] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_client
[Value] => latin1
)
)
[1] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_connection
[Value] => latin1
)
)
[2] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_database
[Value] => utf8
)
)
[3] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_results
[Value] => latin1
)
)
[4] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_server
[Value] => utf8
)
)
[5] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_set_system
[Value] => utf8
)
)
[6] => Array
(
[VARIABLES] => Array
(
[Variable_name] => character_sets_dir
[Value] => D:\Program Files\MySQL\MySQL Server
5.0\share\charsets\
)
)
)
The character_set_client,character_set_results,character_set_connection
is Laten1, and the other is utf8. I think the problem is here. So I
continue the test:
When I query the data in the utf8 table by convert the field to laten1
encoding, I can get the right chinese string. The SQL is:
SELECT CONVERT(myField USING utf8) from myUtf8Table;
How can I change the database connection setting to solve this problem?
Should I modify the core code?