Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
The MySQL UTF8 Issue
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  19 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bentryster@gmail.com  
View profile  
 More options Apr 10 2006, 10:29 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Mon, 10 Apr 2006 07:29:07 -0700
Local: Mon, Apr 10 2006 10:29 am
Subject: The MySQL UTF8 Issue
    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?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RosSoft  
View profile  
 More options Apr 10 2006, 4:30 pm
From: "RosSoft" <ross...@gmail.com>
Date: Mon, 10 Apr 2006 20:30:23 -0000
Local: Mon, Apr 10 2006 4:30 pm
Subject: Re: The MySQL UTF8 Issue
    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mihailo Stefanovic  
View profile  
(2 users)  More options Apr 10 2006, 8:05 pm
From: "Mihailo Stefanovic" <mstefano...@gmail.com>
Date: Tue, 11 Apr 2006 02:05:08 +0200
Local: Mon, Apr 10 2006 8:05 pm
Subject: Re: The MySQL UTF8 Issue
I had the same problem (with Cyrillic letters), and only/most elegant
solution I found was to modify the core.

Try this: in file "cake/libs/model/dbo/dbo_mysql.php" find function
connect(). Replace these lines:

        if (mysql_select_db($config['database'], $this->connection))
        {
            $this->connected = true;
        }

with this:

        if (mysql_select_db($config['database'], $this->connection))
        {
            mysql_query("SET names utf8");
            $this->connected = true;
        }

I wish there was more elegant solution, without modifying the core.
Perhaps another setting in DATABASE_CONFIG (app/config/database.php),
something like:

    var $default = array('driver'    => 'mysql',
                         'connect'  => 'mysql_connect',
                         'host'     => 'localhost',
                         'login'    => 'user',
                         'password' => 'password',
                         'database' => 'project_name',
                         'charset' => 'utf8',
                         'prefix'    => '');


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mika  
View profile  
 More options Apr 11 2006, 12:48 am
From: "Mika" <mmihajlo...@gmail.com>
Date: Mon, 10 Apr 2006 21:48:57 -0700
Local: Tues, Apr 11 2006 12:48 am
Subject: Re: The MySQL UTF8 Issue
I think this is a good idea. Why not make a ticket for it in trac?
(https://trac.cakephp.org/)

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile  
 More options Apr 11 2006, 3:02 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Tue, 11 Apr 2006 00:02:24 -0700
Local: Tues, Apr 11 2006 3:02 am
Subject: Re: The MySQL UTF8 Issue
Thanks for everyone. I have made the ticket for this problem.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Waidelich  
View profile  
 More options Apr 11 2006, 4:20 am
From: "Andreas Waidelich" <andreas.waidel...@gmail.com>
Date: Tue, 11 Apr 2006 10:20:34 +0200
Local: Tues, Apr 11 2006 4:20 am
Subject: Re: The MySQL UTF8 Issue
I used my AppModel to solve the issue.

function __construct()
        {
                $this->execute("SET NAMES 'utf8'");
                parent::__construct();

        }

2006/4/11, bentrys...@gmail.com <bentrys...@gmail.com>:

> Thanks for everyone. I have made the ticket for this problem.

--

e> andreas.waidel...@gmail.com
w> http://andreas-waidelich.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile  
 More options Apr 11 2006, 10:06 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Tue, 11 Apr 2006 07:06:18 -0700
Local: Tues, Apr 11 2006 10:06 am
Subject: Re: The MySQL UTF8 Issue
Andreas:
    Is any Model should add  $this->execute("SET NAMES 'utf8'"); ?
   Or only one model is enough?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Waidelich  
View profile  
 More options Apr 11 2006, 10:24 am
From: "Andreas Waidelich" <andreas.waidel...@gmail.com>
Date: Tue, 11 Apr 2006 16:24:19 +0200
Local: Tues, Apr 11 2006 10:24 am
Subject: Re: The MySQL UTF8 Issue
You just have to do it once in your AppModel (located in your
application's root directory).

my AppModel looks like this:

class AppModel extends Model
{
  function __construct()
  {
    $this->execute("SET NAMES 'UTF8');
    parent::__construct();
  }

}

2006/4/11, bentrys...@gmail.com <bentrys...@gmail.com>:

> Andreas:
>     Is any Model should add  $this->execute("SET NAMES 'utf8'"); ?
>    Or only one model is enough?

--

e> andreas.waidel...@gmail.com
w> http://andreas-waidelich.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile  
 More options Apr 11 2006, 10:31 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Tue, 11 Apr 2006 07:31:12 -0700
Local: Tues, Apr 11 2006 10:31 am
Subject: Re: The MySQL UTF8 Issue
Andreas:
When I add the __construct() function into my model. I got this error:

Fatal error: Call to a member function fetchAll() on a non-object in
D:\php-5.0.4-Win32\PHP_Script\PHP_CAKE\cake\libs\model\model_php5.php
on line 1143

I don't know why.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Waidelich  
View profile  
 More options Apr 11 2006, 10:50 am
From: "Andreas Waidelich" <andreas.waidel...@gmail.com>
Date: Tue, 11 Apr 2006 16:50:51 +0200
Local: Tues, Apr 11 2006 10:50 am
Subject: Re: The MySQL UTF8 Issue
Can you paste your code, please.

2006/4/11, bentrys...@gmail.com <bentrys...@gmail.com>:

> Andreas:
> When I add the __construct() function into my model. I got this error:

> Fatal error: Call to a member function fetchAll() on a non-object in
> D:\php-5.0.4-Win32\PHP_Script\PHP_CAKE\cake\libs\model\model_php5.php
> on line 1143

> I don't know why.

--

e> andreas.waidel...@gmail.com
w> http://andreas-waidelich.de
m> +49.177.423 09 48


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RosSoft  
View profile  
 More options Apr 11 2006, 1:02 pm
From: "RosSoft" <ross...@gmail.com>
Date: Tue, 11 Apr 2006 17:02:38 -0000
Local: Tues, Apr 11 2006 1:02 pm
Subject: Re: The MySQL UTF8 Issue
If you overwrite the model constructor, then you have to call parent's
one

Have you done parent::__construct () ?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile  
 More options Apr 12 2006, 8:28 pm
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Wed, 12 Apr 2006 17:28:59 -0700
Local: Wed, Apr 12 2006 8:28 pm
Subject: Re: The MySQL UTF8 Issue
 Thanks Andreas  , I add the code in the model int the model directory,
so it can't work.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bentryster@gmail.com  
View profile  
 More options Apr 15 2006, 10:28 am
From: "bentrys...@gmail.com" <bentrys...@gmail.com>
Date: Sat, 15 Apr 2006 07:28:52 -0700
Local: Sat, Apr 15 2006 10:28 am
Subject: Re: The MySQL UTF8 Issue
Andreas
But I found it can't work. The error

Fatal error: Call to a member function fetchAll() on a non-object in
D:\php-5.0.4-Win32\PHP_Script\PHP_CAKE\cake\libs\model\model_php5.php
on line 1143

will occur though I add you appmodel in my app_model.php in the cake
directory. I think It can't execute any sql statment in model
constructor. Because the database connection hasn't be created. So the
error occur.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nate  
View profile  
(1 user)  More options Apr 22 2006, 11:49 pm
From: "nate" <nate.ab...@gmail.com>
Date: Sat, 22 Apr 2006 20:49:51 -0700
Local: Sat, Apr 22 2006 11:49 pm
Subject: Re: The MySQL UTF8 Issue
You have it in the wrong order.  Do this:

class AppModel extends Model
{
  function __construct()
  {
    parent::__construct();
    $this->execute("SET NAMES 'UTF8');
  }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
up0  
View profile  
 More options May 1 2006, 10:06 pm
From: "up0" <coconutstu...@gmail.com>
Date: Tue, 02 May 2006 02:06:30 -0000
Local: Mon, May 1 2006 10:06 pm
Subject: Re: The MySQL UTF8 Issue
Thanks for the tip. I've finally gotten my Korean website working with
it as well.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Waidelich  
View profile  
 More options Sep 4 2006, 3:42 am
From: "Andreas Waidelich" <andreas.waidel...@gmail.com>
Date: Mon, 4 Sep 2006 09:42:53 +0200
Local: Mon, Sep 4 2006 3:42 am
Subject: Re: The MySQL UTF8 Issue
to reduce the number of SET NAMES queries add a static boolean
variable to your AppModel an set it to false. Check the value of the
variable in your constructor and execute SET NAMES only, if it has not
been done before. E.g.

class AppModel extends Model{
        static $utf8IsSet = false;

        function __construct(){
                if(!self::$utf8IsSet) {
                        $this->execute("SET NAMES 'utf8'");
                        self::$utf8IsSet = true;        
                }
                parent::__construct();
        }

}

--

e> andreas.waidel...@gmail.com
w> http://andreas-waidelich.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nate  
View profile  
 More options Sep 4 2006, 10:08 am
From: "nate" <nate.ab...@gmail.com>
Date: Mon, 04 Sep 2006 14:08:23 -0000
Local: Mon, Sep 4 2006 10:08 am
Subject: Re: The MySQL UTF8 Issue
Cake 1.2 now supports this natively.  Just add 'encoding' => 'UTF-8' to
your database configuration and the querying is taken care of
automatically at the database level.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andreas Waidelich  
View profile  
 More options Sep 4 2006, 10:23 am
From: "Andreas Waidelich" <andreas.waidel...@gmail.com>
Date: Mon, 4 Sep 2006 16:23:55 +0200
Local: Mon, Sep 4 2006 10:23 am
Subject: Re: The MySQL UTF8 Issue
sounds good. looking forward to Cake 1.2.

2006/9/4, nate <nate.ab...@gmail.com>:

> Cake 1.2 now supports this natively.  Just add 'encoding' => 'UTF-8' to
> your database configuration and the querying is taken care of
> automatically at the database level.

--

e> andreas.waidel...@gmail.com
w> http://andreas-waidelich.de
m> +49.177.423 09 48


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nate  
View profile  
 More options Sep 4 2006, 10:49 am
From: "nate" <nate.ab...@gmail.com>
Date: Mon, 04 Sep 2006 14:49:50 -0000
Local: Mon, Sep 4 2006 10:49 am
Subject: Re: The MySQL UTF8 Issue
    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google