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


Ignore:
Timestamp:
Mar 4, 2024 12:30:57 AM (2 months ago)
Author:
anonymous
Message:

Enable setting db_timezone during runtime. Refactor setParam() in App, DB, and PDO.

File:
1 edited

Legend:

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

    r724 r810  
    119119     * @param  array    $params     Array of parameters (key => val pairs).
    120120     */
    121     public function setParam($params)
    122     {
    123         $app =& App::getInstance();
    124 
    125         if (isset($params) && is_array($params)) {
    126             // Merge new parameters with old overriding only those passed.
    127             $this->_params = array_merge($this->_params, $params);
    128         } else {
    129             $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     121    public function setParam(Array $params)
     122    {
     123        if (!isset($params) || !is_array($params)) {
     124            trigger_error(sprintf('%s failed; not an array: %s', __METHOD__, getDump($params, false, SC_DUMP_PRINT_R)), E_USER_ERROR);
     125        }
     126
     127        // Merge new parameters with old overriding only those passed.
     128        $this->_params = array_merge($this->_params, $params);
     129
     130        if ($this->isConnected()) {
     131            // Params that require additional processing if set during runtime.
     132            foreach ($params as $key => $val) {
     133                switch ($key) {
     134                case 'timezone':
     135                    // Set timezone used by MySQL.
     136                    $this->query(sprintf("SET time_zone = '%s';", $this->escapeString($val)));
     137                    break;
     138                }
     139            }
    130140        }
    131141    }
Note: See TracChangeset for help on using the changeset viewer.