Thomas Bruederli
2012-05-26 b4b5ba7e9da8879d07d41e23b6fd0f6ace104da4
Add getter for database runtime/config variables
1 files modified
26 ■■■■■ changed files
program/include/rcube_mdb2.php 26 ●●●●● patch | view | raw | blame | history
program/include/rcube_mdb2.php
@@ -48,6 +48,7 @@
    private $a_query_results = array('dummy');
    private $last_res_id = 0;
    private $tables;
    private $variables;
    /**
@@ -214,6 +215,31 @@
    /**
     * Get database runtime variables
     *
     * @param string Variable name
     * @param mixed  Default value if var is not set
     * @return mixed Variable value or default
     */
    public function get_variable($varname, $default = null)
    {
        if (!isset($this->variables)) {
            $this->variables = array();
            // only mysql and postgres are know to support this
            if ($this->db_provider == 'pgsql' || $this->db_provider == 'mysql' || $this->db_provider == 'mysqli') {
                $this->db_connect('r');
                $query = $this->db_provider == 'pgsql' ? 'SHOW ALL' : 'SHOW VARIABLES';
                foreach ((array)$this->db_handle->queryAll($query) as $row)
                    $this->variables[$row[0]] = $row[1];
            }
        }
        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
    }
    /**
     * Execute a SQL query
     *
     * @param  string  SQL query to execute