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.

Archive /

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

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

Russian Unicode problem. What to do?


Reply


26 Posts   73396 Views

Avatar
Craneway

20 Posts

2 February 2008 at 8:21am

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.

Avatar
SiSt

Community Member, 5 Posts

6 February 2008 at 12:54am

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

Avatar
Legallydead

2 Posts

10 February 2008 at 10:24pm

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?

Avatar
Craneway

20 Posts

12 February 2008 at 2:54am

Edited: 12/02/2008 3:03am

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.

Avatar
Legallydead

2 Posts

17 February 2008 at 10:04am

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

Avatar
WebSpilka

Community Member, 83 Posts

6 March 2008 at 8:59pm

Edited: 06/03/2008 9:00pm

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 [url=http://forum.cmsmadesimple.org/index.php?PHPSESSID=125c403ad9678bfdbc59696de40f3e19&topic=18903.0]CMSMadeSimple [/url], probably it will help
I want to try now to establish SilverStripe on Unix a hosting

Avatar
WebSpilka

Community Member, 83 Posts

6 March 2008 at 9:23pm

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

Avatar
WebSpilka

Community Member, 83 Posts

6 March 2008 at 9:31pm

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