From 26d857447f5a9d2e8a9c44fd5707a18523926e1d Mon Sep 17 00:00:00 2001 From: alecpl Date: Sat, 9 May 2009 20:07:10 +0000 Subject: - Fix session handling on non-session SQL query error (#1485734) --- program/include/rcube_mdb2.php | 16 +++++++++++++++- program/include/session.inc | 16 ---------------- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'program/include') diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php index 713ff4255..b1e5fff80 100644 --- a/program/include/rcube_mdb2.php +++ b/program/include/rcube_mdb2.php @@ -177,6 +177,17 @@ class rcube_mdb2 } + /** + * Connection state checker + * + * @param boolean True if in connected state + */ + function is_connected() + { + return PEAR::isError($this->db_handle) ? false : true; + } + + /** * Execute a SQL query * @@ -187,6 +198,9 @@ class rcube_mdb2 */ function query() { + if (!$this->is_connected()) + return NULL; + $params = func_get_args(); $query = array_shift($params); @@ -360,7 +374,7 @@ class rcube_mdb2 */ function _fetch_row($result, $mode) { - if ($result === FALSE || PEAR::isError($result)) + if ($result === FALSE || PEAR::isError($result) || !$this->is_connected()) return FALSE; return $result->fetchRow($mode); diff --git a/program/include/session.inc b/program/include/session.inc index 983d01587..d75b303b3 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -39,10 +39,6 @@ function rcube_sess_read($key) $DB = rcmail::get_instance()->get_dbh(); - if ($DB->is_error()) { - return false; - } - $sql_result = $DB->query( "SELECT vars, ip, " . $DB->unixtimestamp('changed') . " AS changed FROM " . get_table_name('session') . " @@ -66,10 +62,6 @@ function rcube_sess_write($key, $vars) { $DB = rcmail::get_instance()->get_dbh(); - if ($DB->is_error()) { - return false; - } - $sql_result = $DB->query( "SELECT 1 FROM " . get_table_name('session') . " WHERE sess_id=?", @@ -105,10 +97,6 @@ function rcube_sess_destroy($key) $rcmail = rcmail::get_instance(); $DB = $rcmail->get_dbh(); - if ($DB->is_error()) { - return false; - } - $DB->query("DELETE FROM " . get_table_name('session') . " WHERE sess_id=?", $key); return true; @@ -121,10 +109,6 @@ function rcube_sess_gc($maxlifetime) $rcmail = rcmail::get_instance(); $DB = $rcmail->get_dbh(); - if ($DB->is_error()) { - return false; - } - // just delete all expired sessions $DB->query("DELETE FROM " . get_table_name('session') . " WHERE changed < " . $DB->fromunixtime(time() - $maxlifetime)); -- cgit v1.2.3