Changeset 683 for trunk/lib/DB.inc.php


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

Add support for mysql-specific character sets and collations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.