Jump to:

327 Posts in 211 Topics by 159 members

Migrating a Site to Silverstripe

SilverStripe Forums » Migrating a Site to Silverstripe » UTF-8 problem when migrating data

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

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

Page: 1 2 3
Go to End
Author Topic: 10850 Views
  • pixelmin
    Avatar
    Community Member
    16 Posts

    Re: UTF-8 problem when migrating data Link to this post

    Hi!

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

  • pixelmin
    Avatar
    Community Member
    16 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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

  • brokemeister
    Avatar
    Community Member
    30 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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.

  • Radon
    Avatar
    Community Member
    11 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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 );

  • brokemeister
    Avatar
    Community Member
    30 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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");

  • kurthv
    Avatar
    Community Member
    2 Posts

    Re: UTF-8 problem when migrating data Link to this post

    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

    10850 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.