diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2012-05-26 15:28:44 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2012-05-26 15:28:44 +0200 |
commit | b4b5ba7e9da8879d07d41e23b6fd0f6ace104da4 (patch) | |
tree | f36b76f831d76b72914027c1fc9e699ae14a2611 /program | |
parent | fa5f3f26f938ec8ddf7db8e9401e0e4363decfb7 (diff) |
Add getter for database runtime/config variables
Diffstat (limited to 'program')
-rw-r--r-- | program/include/rcube_mdb2.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php index 6acb3a03d..a255d9e6e 100644 --- a/program/include/rcube_mdb2.php +++ b/program/include/rcube_mdb2.php @@ -48,6 +48,7 @@ class rcube_mdb2 private $a_query_results = array('dummy'); private $last_res_id = 0; private $tables; + private $variables; /** @@ -214,6 +215,31 @@ class rcube_mdb2 /** + * 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 |