Index: /trunk/roundcubemail/index.php
===================================================================
--- /trunk/roundcubemail/index.php	(revision 163)
+++ /trunk/roundcubemail/index.php	(revision 164)
@@ -3,5 +3,5 @@
  +-----------------------------------------------------------------------+
  | RoundCube Webmail IMAP Client                                         |
- | Version 0.1-20060220                                                  |
+ | Version 0.1-20060314                                                  |
  |                                                                       |
  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
@@ -111,4 +111,13 @@
 load_gui();
 
+
+// check DB connections and exit on failure
+if ($err_str = $DB->is_error())
+  {
+  raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
+                    'message' => $err_str), FALSE, TRUE);
+  }
+
+
 // error steps
 if ($_action=='error' && !empty($_GET['_code']))
Index: /trunk/roundcubemail/program/include/main.inc
===================================================================
--- /trunk/roundcubemail/program/include/main.inc	(revision 163)
+++ /trunk/roundcubemail/program/include/main.inc	(revision 164)
@@ -75,8 +75,10 @@
   $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr']);
   $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql';
+  $DB->db_connect('w');
+    
 
   // we can use the database for storing session data
   // session queries do not work with MDB2
-  if ($CONFIG['db_backend']!='mdb2' && is_object($DB))
+  if ($CONFIG['db_backend']!='mdb2' && !$DB->is_error())
     include_once('include/session.inc');
 
Index: /trunk/roundcubemail/program/include/rcube_db.inc
===================================================================
--- /trunk/roundcubemail/program/include/rcube_db.inc	(revision 163)
+++ /trunk/roundcubemail/program/include/rcube_db.inc	(revision 164)
@@ -36,5 +36,5 @@
  * @author     David Saez Padros <david@ols.es>
  * @author     Thomas Bruederli <roundcube@gmail.com>
- * @version    1.16
+ * @version    1.17
  * @link       http://pear.php.net/package/DB
  */
@@ -46,4 +46,7 @@
   var $db_mode = '';          // Connection mode
   var $db_handle = 0;         // Connection handle
+  var $db_pconn = false;      // Use persistent connections
+  var $db_error = false;
+  var $db_error_msg = '';
 
   var $a_query_results = array('dummy');
@@ -57,5 +60,5 @@
    * @param  string  Optional DSN for read only operations
    */
-  function __construct($db_dsnw, $db_dsnr='')
+  function __construct($db_dsnw, $db_dsnr='', $pconn=false)
     {
     if ($db_dsnr=='')
@@ -64,4 +67,5 @@
     $this->db_dsnw = $db_dsnw;
     $this->db_dsnr = $db_dsnr;
+    $this->db_pconn = $pconn;
         
     $dsn_array = DB::parseDSN($db_dsnw);
@@ -75,7 +79,7 @@
    * @see  rcube_db::__construct
    */
-  function rcube_db($db_dsnw,$db_dsnr='')
-    {
-    $this->__construct($db_dsnw,$db_dsnr);
+  function rcube_db($db_dsnw, $db_dsnr='', $pconn=false)
+    {
+    $this->__construct($db_dsnw, $db_dsnr);
     }
 
@@ -91,10 +95,15 @@
     {
     // Use persistent connections if available
-    $dbh = DB::connect($dsn, array('persistent' => TRUE));
+    $dbh = DB::connect($dsn, array('persistent' => $this->db_pconn));
         
     if (DB::isError($dbh))
       {
+      $this->db_error = TRUE;
+      $this->db_error_msg = $dbh->getMessage();
+
       raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
-                        'message' => $dbh->getMessage()), TRUE, FALSE);
+                        'message' => $this->db_error_msg), TRUE, FALSE);
+                        
+      return FALSE;
       }
 
@@ -143,5 +152,16 @@
 
     $this->db_handle = $this->dsn_connect($dsn);
-    $this->db_connected = true;
+    $this->db_connected = $this->db_handle ? TRUE : FALSE;
+    }
+    
+    
+  /**
+   * Getter for error state
+   *
+   * @param  boolean  True on error
+   */
+  function is_error()
+    {
+    return $this->db_error ? $this->db_error_msg : FALSE;
     }
 
@@ -204,4 +224,7 @@
         
     $this->db_connect($mode);
+    
+    if (!$this->db_connected)
+      return FALSE;
 
     if ($this->db_provider == 'sqlite')
