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


Ignore:
Timestamp:
Jan 28, 2019 10:51:50 PM (5 years ago)
Author:
anonymous
Message:

Reduce timezone support to simply setting defaults for user, php, and mysql (all UTC), just to ensure consistency

File:
1 edited

Legend:

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

    r659 r660  
    6969        'zero_date' => '0000-00-00',
    7070        'infinity_date' => '9999-12-31',
     71
     72        // Timezone for MySQL.
     73        'timezone' => 'UTC',
    7174    );
    7275
     
    189192        $this->_connected = true;
    190193
     194        $init_sql = array();
     195
    191196        // Tell MySQL what character set we're using. Available only on MySQL versions > 4.01.01.
    192197        if ('' != $app->getParam('character_set') && isset($this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))])) {
    193             $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))] . "' */");
     198            $init_sql[] = sprintf("SET NAMES '%s'", $this->mysql_character_sets[mb_strtolower($app->getParam('character_set'))]);
    194199        } else {
    195200            $app->logMsg(sprintf('%s is not a known character_set.', $app->getParam('character_set')), LOG_ERR, __FILE__, __LINE__);
     
    201206        }
    202207
    203         // Set timezone.
    204         $tz = date_default_timezone_get();
    205         // Check that PHP is configured with a valid timezone name, e.g., "UTC" or "America/Mexico_City" or "-6:00".
    206         if ($app->getParam('timezone') && $app->getParam('timezone') == $tz && preg_match('!^([A-Z_/-]{3,}|[-+\d:]+)$!i', $tz)) {
     208        // Set MySQL session timezone.
     209        if ($this->getParam('timezone')) {
    207210            // https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
    208             $this->query(sprintf("SET SESSION time_zone = '%s'", $tz));
     211            $init_sql[] = sprintf("SET time_zone = '%s'", $this->getParam('timezone'));
     212        }
     213
     214        // Run init query, if set.
     215        if (!empty($init_sql)) {
     216            $this->query(join('; ', $init_sql));
    209217        }
    210218
     
    506514    }
    507515
    508 
    509516} // End.
    510517
Note: See TracChangeset for help on using the changeset viewer.