From b4b5ba7e9da8879d07d41e23b6fd0f6ace104da4 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Sat, 26 May 2012 09:28:44 -0400
Subject: [PATCH] Add getter for database runtime/config variables
---
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 6acb3a0..a255d9e 100644
--- a/program/include/rcube_mdb2.php
+++ b/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
--
Gitblit v1.9.1