We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43957
    • 79 Posts
    I have exported my MODX (2.2.6pl) database many-a-time and have find strange characters intermingled with my content, like  ”

    I have just discovered that the database charset is blank in config.inc.php:

    $database_connection_charset = '';


    Maybe a foolish mistake I made when installing MODX? The live site is currently fine, but if I correct the charset to 'utf8' in config.inc.php then the strange characters appear on the site and there are hundreds of pages like this.

    I've had a look at http://bobsguides.com/convert-db-utf8.html, but I'm not sure if this will help me.

    I've looked in the database dump and notice:
    ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    , rather than just being utf8

    Can anyone suggest a method to help fix this issue? [ed. note: dave-b last edited this post 13 years, 3 months ago.]
      • 3749
      • 24,544 Posts
      In config.inc.php, check the character set in both these lines:

      $database_connection_charset = 'utf8';
      $database_dsn = 'mysql:host=localhost;dbname=some_name;charset=utf8';
      

      Look at the database in PhpMyAdmin and use the "structure" tab to check the character set of the individual tables and the the text fields within the tables.

      If they're not all set to utf8, my conversion script *may* help you, but it's possible that something that happened earlier has corrupted the database.

      The AUTO_INCREMENT=1 is normal.

      Worst case: Use my script and then do a painful search-and-replace on the exported SQL and then import it.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 43957
        • 79 Posts
        The charset in config.inc.php is blank in both cases:

        $database_connection_charset = '';
        $database_dsn = 'mysql:host=localhost;dbname=some_name;charset=';


        Maybe this happened at some point when I updated MODX and it didn't set the charset?

        I have been through everything in the database and all text and chars are utf8_general_ci

        If I change the config.inc.php so that they are utf8, then the strange characters appear throughout the content.

        I have a feeling that I will have to add the utf8 to config.inc.php and then remove all the weird characters, either by manually editing the resources, or like you say, export the database and delete them then reimport.

        Doing a find and replace would be tricky, as an example one line in the database:

        INSERT INTO `modx_site_content` VALUES(17, 'document', 'text/html',...............

        contains all these odd characters: ‘flyer’ CV’s,

        However, they only appear in modx_site_content, so something I can manually and painstakingly remove by editing the resources I guess?
          • 3749
          • 24,544 Posts
          Did you maybe paste the Resource content from Word or something similar?

          It might actually be easier to just retype each paragraph in the manager and delete the existing ones. Be sure to set the character set to 'utf8' in both places in config.inc.php first.

          Another possible fix would be to paste the text into a stupid text editor (e.g., notepad -- especially a very old version of notepad), which might just throw away the weird characters for you.

          Also, PhpEd from NuSphere will ask you if you want to "transliterate" files when it loads them, though I haven't found it to work on the kind of problems I've had. It might work for you though. I think they have a free trial.

          PhpStorm from JetBrains lets you set the character encoding of each file, so you could use it to experiment with different character sets.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 43957
            • 79 Posts
            Hi Bob,

            Thanks for your response. I'm pretty sure it's come about from not having the character set in config.inc.php. It seems that many of the resources that use TinyMCE as rich text have the majority of the strange characters when setting the character set to utf8, but not in all cases.

            I can set the utf8 in config.inc.php and manually edit each of the resource content, when I have a good few hours on my hands, so it's not the end of the world.

            Just have to be more careful in future and ensure that it's correctly configured in the config file in the first place. smiley

              • 3749
              • 24,544 Posts
              The empty character set in config.inc.php is really strange. I've never heard of that happening. The only way I think it could happen is if you did an advanced install and accidentally blanked it out.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 43957
                • 79 Posts
                I've now fixed my site character set by setting it correctly in config.inc.php and then manually trawling through each page and deleting the odd characters.

                I also updated to 2.2.8, but I've never used the advanced install option, so I'm not sure how it would have blanked the character set.

                It seems that the strange characters replaced apostrophies ' and hyphens -, and few others appeared here and there. Took a few hours, but all tidied up now.