Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Migrating a Site to Silverstripe /

What you need to know when migrating your existing site to SilverStripe.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

UTF-8 problem when migrating data


Reply


20 Posts   11344 Views

Avatar
pixelmin

Community Member, 16 Posts

25 May 2009 at 10:02pm

Hi!

I've the same problem with accents. Is there a solution yet?

Avatar
pixelmin

Community Member, 16 Posts

25 May 2009 at 10:25pm

Ok, reply to myself.

I've found a weird solution.

I'm using EMS MYSQL Manager to manage my silverstripe db. When I export the database, it opens "sql monitor" with all the sql code and creates a .sql file too. In that file the charset isn't correct.
So, when I import the db in another host, I copy the text on the sql monitor (in the program I use) instead that .sql file.

I'm not sure if I explained it correctly, my english isn't really good :)

Avatar
brokemeister

Community Member, 30 Posts

2 June 2009 at 9:38pm

Hi @all,

I had the same problem...

Some MySQL-servers created a ISO connection by default.

So, you must call

mysql_query("SET NAMES 'utf8'");

directly after the connection to the db.

=> A parameter for enforcing a utf8-connection would be pretty useful.

Cheers,

Malte

Avatar
Ingo

Forum Moderator, 801 Posts

5 June 2009 at 8:13am

Just for reference, here's the ticket relating to the issue, with an explanation from Sam, the project lead: http://open.silverstripe.com/ticket/2377. Unfortunately we can't simply switch connections by default without effect on legacy data, although I agree that it would be a nice optional setting for new sites in the meantime.

Avatar
Radon

Community Member, 11 Posts

11 June 2009 at 12:02am

Hi,
a usual source of utf-8 problems with mysql is the mysql connection (mysql needs to be set to utf-8 on a per connection basis).
2 solutions:
Add these lines to your [mysqld] - section of my.cnf:
default-character-set = utf8
default-collation = utf8_general_ci
init_connect='SET NAMES utf8'

or run the following sql commands directly after connecting to the database:
mysql_query( 'SET NAMES utf8', $db_ss );
mysql_query( 'SET CHARACTER SET utf8', $db_ss );
mysql_query( "SET COLLATION_CONNECTION='utf8_general_ci'", $db_ss );

Avatar
brokemeister

Community Member, 30 Posts

11 June 2009 at 12:37am

Edited: 11/06/2009 12:38am

Just a simple and clean solution:
<br >
<br >Create a class:
<br >class UTF8MySQLDatabase extends MySQLDatabase {
<br >
<br >   public function __construct($parameters) {
<br >      parent::__construct($parameters);
<br >      $this->query("SET CHARACTER SET 'utf8'");
<br >      $this->query("SET NAMES 'utf8'");
<br >   }
<br >}
<br >Add something like that to your "mysite/_config.php":
<br >global $databaseConfig;
<br >$databaseConfig = array(
<br >   "type" => "UTF8MySQLDatabase",
<br >);
<br >
<br >Cheers,
<br >Malte

Avatar
mattclegg

Community Member, 56 Posts

8 March 2011 at 1:21am

I think you mean;

class UTF8MySQLDatabase extends MySQLDatabase {
   public function __construct($parameters) {
      parent::__construct($parameters);
      $this->query("SET CHARACTER SET 'utf8'");
      $this->query("SET NAMES 'utf8'");
   }
}


Add something like that to your "mysite/_config.php":

global $databaseConfig;
$databaseConfig = array("type" => "UTF8MySQLDatabase");

Avatar
kurthv

Community Member, 2 Posts

4 November 2012 at 3:08am

Edited: 04/11/2012 3:09am

I have excatly the same problem!

I did try the following steps:

1) I changed the my.cnf file, like described by Radon.
2) It did place a file 'UTF8MySQLDatabase.php' in the code directoty of mysite and did change the connection type to "UTF8MySQLDatabase" like described by mattclegg.

Unfortunately nothing of this did help :(

Here the the original website (old server): http://www.infokomm.de
And here is the migrated website (new server): http://54.246.96.76/

What's wrong?
I have no idea :(