Changeset b4b5ba7 in github for program/include/rcube_mdb2.php


Ignore:
Timestamp:
May 26, 2012 9:28:44 AM (12 months ago)
Author:
Thomas Bruederli <thomas@…>
Branches:
master, HEAD, dev-browser-capabilities, pdo
Children:
3720282
Parents:
fa5f3f2
Message:

Add getter for database runtime/config variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_mdb2.php

    r041c93c rb4b5ba7  
    4949    private $last_res_id = 0; 
    5050    private $tables; 
     51    private $variables; 
    5152 
    5253 
     
    211212    { 
    212213      return !empty($this->db_dsnr) && $this->db_dsnw != $this->db_dsnr; 
     214    } 
     215 
     216 
     217    /** 
     218     * Get database runtime variables 
     219     * 
     220     * @param string Variable name 
     221     * @param mixed  Default value if var is not set 
     222     * @return mixed Variable value or default 
     223     */ 
     224    public function get_variable($varname, $default = null) 
     225    { 
     226        if (!isset($this->variables)) { 
     227            $this->variables = array(); 
     228 
     229            // only mysql and postgres are know to support this 
     230            if ($this->db_provider == 'pgsql' || $this->db_provider == 'mysql' || $this->db_provider == 'mysqli') { 
     231                $this->db_connect('r'); 
     232                $query = $this->db_provider == 'pgsql' ? 'SHOW ALL' : 'SHOW VARIABLES'; 
     233                foreach ((array)$this->db_handle->queryAll($query) as $row) 
     234                    $this->variables[$row[0]] = $row[1]; 
     235            } 
     236        } 
     237 
     238        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default; 
    213239    } 
    214240 
Note: See TracChangeset for help on using the changeset viewer.