Changeset 683 for trunk/lib


Ignore:
Timestamp:
May 19, 2019 10:51:34 PM (5 years ago)
Author:
anonymous
Message:

Add support for mysql-specific character sets and collations

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r679 r683  
    124124        'user_timezone' => 'UTC',
    125125        'php_timezone' => 'UTC',
    126         'mysql_timezone' => 'UTC',
     126        'db_timezone' => 'UTC',
    127127
    128128        // Use php sessions?
     
    141141        'enable_db_session_handler' => false,
    142142
     143        // db_* parameters are passed to the DB object in $app->start().
    143144        // DB credentials should be set as apache environment variables in httpd.conf, readable only by root.
    144145        'db_server' => null,
     
    146147        'db_user' => null,
    147148        'db_pass' => null,
     149        'db_character_set' => '',
     150        'db_collation' => '',
    148151
    149152        // CLI scripts will need this JSON file in the include path.
     
    427430                'db_debug' => $this->getParam('db_debug'),
    428431                'db_die_on_failure' => $this->getParam('db_die_on_failure'),
    429                 'timezone' => $this->getParam('mysql_timezone'),
     432                'timezone' => $this->getParam('db_timezone'),
     433                'character_set' => $this->getParam('db_character_set'),
     434                'collation' => $this->getParam('db_collation'),
    430435            ));
    431436
  • trunk/lib/DB.inc.php

    r679 r683  
    7272        // Timezone for MySQL.
    7373        'timezone' => 'UTC',
     74
     75        // MySQL character set and collation.
     76        'character_set' => '',
     77        'collation' => '',
    7478    );
    7579
     
    192196        $this->_connected = true;
    193197
    194         // Tell MySQL what character set we're using. Available only on MySQL versions > 4.01.01.
    195         if ('' != $app->getParam('character_set') && isset($this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))])) {
    196             $this->query(sprintf("SET NAMES '%s';", $this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))]));
    197         } else {
    198             $app->logMsg(sprintf('%s is not a known character_set.', $app->getParam('character_set')), LOG_ERR, __FILE__, __LINE__);
     198        // If the mysql charset is not defined, try to determine a mysql charset from the app charset.
     199        if ('' == $this->getParam('character_set') && '' != $app->getParam('character_set') && isset($this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))])) {
     200            $this->setParam(array('character_set' => $this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))]));
     201        }
     202        if ('' != $this->getParam('character_set')) {
     203            if ('' != $this->getParam('collation')) {
     204                $this->query(sprintf("SET NAMES '%s' COLLATE '%s';", $this->getParam('character_set'), $this->getParam('collation')));
     205            } else {
     206                $this->query(sprintf("SET NAMES '%s';", $this->getParam('character_set')));
     207            }
    199208        }
    200209
Note: See TracChangeset for help on using the changeset viewer.