Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Russian Unicode problem. What to do?

Our old forums are still available as a read-only archive.

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

Page: 1 2 3 4
Go to End
Author Topic: 72035 Views
  • Craneway
    Avatar
    20 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    Hi, everyone! The problem with cyrillic characters in utf8 within SilverStripe may be caused by the default parameters of mysql5 of the majority of Russian servers offering shared hosting. The default encoding is set to 'cp1251', which is common for Russian language sites. It makes a lot of trouble with cyrillics output in unicode, when some of the characters appear unreadable.
    One of the possible solution is to modify 3 files in SS distribution before installing it.

    1) install.php
    2) sapphire/core/model/MySQLDatabase.php
    3) sapphire/core/model/DB.php

    Right after function of connection to the database you should insert the following code:

    mysql_query ("set character_set_client='utf8'");
    mysql_query ("set character_set_results='utf8'");
    mysql_query ("set collation_connection='utf8_general_ci'");

    It made my Russian cyrillics characters appear correctly.

  • SiSt
    Avatar
    Community Member
    5 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    We solves our problem by installing a mysql5 server instead of mysql4.11.

  • Legallydead
    Avatar
    2 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    To Craneway:

    Hi! I've got the same problem. But i couldn't figure out where exactly should i insert these lines.
    Can't you make some examples?

  • Craneway
    Avatar
    20 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    Hi, I looked once again through the mysql docs, and figured that one should modify only sapphire/core/model/MySQLDatabase.php (if the site has been already installed) adding just one mysql_query which is the replacement for the 3 mentioned above.
    Look at the lines starting with 38. The code should go like that:

    public function __construct($parameters) {
          $this->dbConn = mysql_connect($parameters['server'], $parameters['username'], $parameters['password']);
          $this->active = mysql_select_db($parameters['database'], $this->dbConn);
          $this->database = $parameters['database'];
          if(!$this->dbConn) {
             $this->databaseError("Couldn't connect to MySQL database");
          }
          mysql_query ("SET CHARACTER SET utf8");
          
          parent::__construct();
       }


    Are you using a shared hosting as well? If you need to install, you should create an empty database first, then go to phpmyadmin (or whatever you use) and manually set the db properties (encoding). Make sure you do that on an empty database, because when it already has data you won't be able to modify it.
    Then modify your install.php in the function starting with the line 392:

    function requireMysqlConnection($server, $username, $password, $testDetails) {
          $this->testing($testDetails);
          $conn = @mysql_connect($server, $username, $password);
          
          if($conn) {
             return true;
             /*
             if(mysql_query("CREATE DATABASE testing123")) {
                mysql_query("DROP DATABASE testing123");
                return true;
             } else {
                $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
                $this->error($testDetails);
             }
             */
          } else {
             $testDetails[2] .= ": " . mysql_error();
             $this->error($testDetails);
          }
          mysql_query ("SET CHARACTER SET utf8");
       }

    When you run the installer, you will get an error in the top of the page, but don't pay attention to this, just enter your db name, password etc. and click "recheck the requirements". Should work as magic.
    Please, reply when done, just to make sure everything is OK.

  • Legallydead
    Avatar
    2 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    Thank you! It worked! Спасибо!

  • fiord
    Avatar
    Community Member
    79 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    I have the same problem on my local Apache.
    Prompt you it has decided?
    I think that a problem in local server configuration, only I do not know what.
    I allow the reference to the same problem in CMSMadeSimple , probably it will help
    I want to try now to establish SilverStripe on Unix a hosting

  • fiord
    Avatar
    Community Member
    79 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    Legallydead можеш добавить меня в аську ?
    ICQ 41151402

  • fiord
    Avatar
    Community Member
    79 Posts

    Re: Russian Unicode problem. What to do? Link to this post

    Craneway
    Thank you! It worked! Спасибо!

    72035 Views
Page: 1 2 3 4
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.