2

During the migration from 2.6 to 3.1 may encounter problems with the display of special characters in the Croatian language. The content is taken from the database.

Content is stored in a database via CakePHP 2.x applications, and can be displayed properly. but when I connect a new application I have a problem with the proper display of these characters čćšđž.

database / tables : MyISAM utf8_general_ci

cakephp 2.x app

public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => '*********',
        'password' => '************',
        'database' => 'apartmani',
    );

core.php

/**
 * Application wide charset encoding
 */
Configure::write('App.encoding', 'UTF-8');

bootstrap.php

Configure::write('Config.language', 'hrv');

cakephp 3.1- rc1

'App' => [
        'namespace' => 'App',
        'encoding' => 'UTF-8',
...

'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            /**
             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
             */
            //'port' => 'nonstandard_port_number',
            'username' => '*********',
            'password' => '***********',
            'database' => 'apartmani',
            'encoding' => 'utf8',
            'timezone' => 'UTC',
            'cacheMetadata' => true,

bootstap.php

/**
 * Set the default locale. This controls how dates, number and currency is
 * formatted and sets the default language to use for translations.
 */
ini_set('intl.default_locale', 'hr');

How to fix this?

Oops D'oh
  • 941
  • 1
  • 15
  • 34
Salines
  • 5,674
  • 3
  • 25
  • 50
  • 1
    Sounds like with 2.6 your db connection was not utf8. That means the data in the db isn't actually utf8 if it's displayed "correctly" with your old app. – AD7six Sep 14 '15 at 10:12
  • @AD7six You're right, I added " 'encoding' => 'utf8' " to 2.6 db connection, and now I have the same problem there, how far out? – Salines Sep 14 '15 at 10:19
  • 1
    You can fix that directly on the db, or write a little script to read all the records using a bad connection (with no utf8 encoding) and write with a good connection (with utf8 encoding). I wrote such a shell a long time ago, if I find it I'll post it as an answer. In summary though: Your app works and you need to fix the data. – AD7six Sep 14 '15 at 10:28
  • 2
    I export db, open sql file in Sublime Text editor, find and replace bad characters, Then import to db. Now all it's ok. – Salines Sep 14 '15 at 11:33
  • 1
    That's an appropriate answer (I.e. make the above comment an answer, add a little more detail, and accept it) =) – AD7six Sep 14 '15 at 17:10

0 Answers0