We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27843
    • 170 Posts
    Silver Zachara Reply #1, 16 years ago
    Hi list,

    For what do you have to use SET CHARACTER SET in manager/index.php and dbapi.mysql.class.inc.php when connecting to the server ?
    I understand the diffrences between this statements.

    I ask because I have problem with utf8 in Czech language, exactly with some letters as Ď ň and so on.

    This problem is for following reasons. My provider’s setting of character_set_database is in defualt setting, so latin1.
    So when is set
    $database_connection_charset = ’utf8’;
    in manager/include/config.inc.php, than I have problem.

    All problems would be resolved, if you use statement
    @mysql_query("SET NAMES {$database_connection_charset}");<br />

    Now I must do core hack, what is uncomfortably.
    What is the purpose of using SET CHARACTER SET instead of SET NAMES ?
    • Quote from: snop at Apr 26, 2008, 12:46 PM

      For what do you have to use SET CHARACTER SET in manager/index.php and dbapi.mysql.class.inc.php when connecting to the server ?
      I understand the diffrences between this statements.

      I ask because I have problem with utf8 in Czech language, exactly with some letters as Ď ň and so on.

      This problem is for following reasons. My provider’s setting of character_set_database is in defualt setting, so latin1.
      So when is set
      $database_connection_charset = ’utf8’;
      in manager/include/config.inc.php, than I have problem.

      All problems would be resolved, if you use statement
      @mysql_query("SET NAMES {$database_connection_charset}");<br />

      Now I must do core hack, what is uncomfortably.
      What is the purpose of using SET CHARACTER SET instead of SET NAMES ?
      SET NAMES forces the connection charset to whatever you specify, which will translate characters between charsets, but that process is lossy. Instead, you should make sure your database container is set the same as your intended character set. SET CHAR SET actually uses the value of the database container to set the connection charset, regardless of what character set you specify for MODx to use. If you ensure that the database container has the proper charset for the data your are storing in the actual tables, and that your database_connection_charset setting in MODx either matches this, or another charset you want to translate the data to/from when talking to the db (though the latter is not recommended), this should work flawlessly.
        • 27843
        • 170 Posts
        Silver Zachara Reply #3, 16 years ago
        Quote from: OpenGeek at Apr 26, 2008, 02:42 PM

        [SET NAMES forces the connection charset to whatever you specify, which
        will translate characters between charsets, but that process is lossy.
        Instead, you should make sure you set your database container name the name of (!)
        your intended character set. SET CHAR SET actually uses the value of
        the database container to set the connection charset, regardless of what
        character set you specify for MODx to use. If you ensure that the
        database container has the proper charset for the data your are storing
        in the actual tables, and that your database_connection_charset setting
        in MODx either matches this, or another charset you want to translate
        the data to/from when talking to the db (though the latter is not
        recommended), this should work flawlessly.

        I understand the principles and diffrences between the SET NAMES and SET CHAR SET. However, the problem is that the administrator of my webhosting is dumb (don’t want to call him stupid) and for some reasons doesn’t want to change the default-character-set to utf8, though the tables (there are 10 of them smiley ) of the MySql server were encoded in utf8.
        I think such difficulties should be solved by MODx. I propose to include some setting in manager/include/config.inc.php e.g.
        $database_connection_method=’SET CHARACTER SET’;
        in deafault
        and if there will be a need, everyone can change the setting to
        $database_connection_method=’SET NAMES’;

        So the starting line of the config will be looking like this
        /** <br />* MODx Configuration file <br />*/ <br />$database_type = ’mysql’; <br />$database_server = ’localhost’; <br />$database_user = ’root’; <br />$database_password = ’15delfinu’; <br />$database_connection_charset = ’utf8’; <br />$database_connection_method = ’SET CHARACTER SET’; <br />$dbase = ’`modx`’; <br />$table_prefix = ’modx_’; <br />error_reporting(E_ALL & ~E_NOTICE);

        This setting could be used also for the choice of the MOdx installation and that is, in the
        Advanced Upgrade Install (edit database config) e.g. Connection
        method:
        of course with the default setting SET CHARACTER SET.
        If you were interested in this modification I could program and offer e.g. diffs.
        Of course, I would make changes in all the necessary files.
        install/instprocessor.php <br />install/sqlParser.class.php <br />manager/actions/bkmanager.static.php <br />manager/includes/extenders/dbapi.mysql.class.inc.php <br />manager/includes/veriword.php <br />manager/index.php <br />manager/media/browser/mcpuk/connectors/php/config.php <br />manager/media/ImageEditor/config.inc.php <br />manager/processors/login.processor.php

        • That sounds like a perfectly acceptable solution; if you can create a patch to submit, we would be more than happy to review it for inclusion in future 0.9.6.x releases.
            • 27843
            • 170 Posts
            Silver Zachara Reply #5, 16 years ago
            If I will have time I do it. The changes i will do on the newset release, but now I need to know which files have to be modified.

            Of course I will change this files.
            install/instprocessor.php <br />install/sqlParser.class.php<br />manager/actions/bkmanager.static.php<br />manager/includes/extenders/dbapi.mysql.class.inc.php<br />manager/includes/veriword.php <br />manager/index.php<br />manager/media/ImageEditor/config.inc.php<br />manager/processors/login.processor.php


            But what about these files ?
            manager/media/browser/mcpuk/connectors/php/config.php<br />assets/snippets/AjaxSearch/includes/AjaxSearch.inc.php

            If I modife these files now, in the next realeases of this programs (in the case of AjaxSearch of course snippet) the changes will be discarded.
              • 9130
              • 171 Posts
              Very nice,

              I was having similar problems on a few of my sites and ended up hardcoding SET NAMES into the files since nothing else seemed to work. I’d love to see this included in the core.
              • Quote from: snop at Apr 28, 2008, 04:16 PM

                But what about these files ?
                manager/media/browser/mcpuk/connectors/php/config.php<br />assets/snippets/AjaxSearch/includes/AjaxSearch.inc.php

                If I modife these files now, in the next realeases of this programs (in the case of AjaxSearch of course snippet) the changes will be discarded.

                If you prepare the patch, we’ll get it in the core. Ping coroico re: the Ajax Search bit and bravado for the mcpuck tweaks.
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 27843
                  • 170 Posts
                  I’ll do this patch tomorrow or on the next weekend.

                  Quote from: rthrash at May 19, 2008, 01:41 PM

                  Quote from: snop at Apr 28, 2008, 04:16 PM

                  But what about these files ?
                  manager/media/browser/mcpuk/connectors/php/config.php<br />assets/snippets/AjaxSearch/includes/AjaxSearch.inc.php

                  If I modife these files now, in the next realeases of this programs (in the case of AjaxSearch of course snippet) the changes will be discarded.

                  If you prepare the patch, we’ll get it in the core. Ping coroico re: the Ajax Search bit and bravado for the mcpuck tweaks.

                  But I don’t understand this - Ping coroico re: the Ajax Search bit and bravado for the mcpuck tweaks., so i don’t know if i have to do the patch for Ajax search and Mcpuck.

                  Thank you for your explanation.
                    • 27843
                    • 170 Posts
                    Hello,

                    I’ve finished the patch. I checkout the current trunk from http://svn.modxcms.com/svn/tattoo/tattoo/trunk/ and I did changes on 3741 revision.
                    My PHP Ide automatically substitute \n at the end of the lines to \r\n and I can’t disable this feature, so sorry for this.

                    New Installation and Upgrade Existing Install process is finally finished in the patch. In these parts of the installation SET CHRACTER SET is used by default and user can’t affect, wheter SET CHRACTER SET or SET NAMES will be used. To be sure that you can change this behavior, you can add some <input /> or <select /> in this screen - install/index.php?action=connection

                    But Advanced Upgrade Install isn’t finished, because this part of the installation isn’t functional and can’t be finished now. When this part of the installation will be functional I finish up this.

                    I had problems with adding all the language files to the patch, because they are in different encodings, thus I added only install/lang/english/english.inc.php file.
                      • 27843
                      • 170 Posts
                      I looked at the Advanced Upgrade Install in detail and found why does not work. This is in the Firefox Error console

                      Error: $("database_collation") is null<br />Source file: http://localhost/modx-096/install/connection.js<br />Line: 12

                      The error is clear.
                      I hope that this error will be fixed in MODx 0.9.6.2-rc2 that I could finish this patch for the best CMS I know.  wink