Changeset 164 in subversion


Ignore:
Timestamp:
Mar 14, 2006 4:13:07 PM (7 years ago)
Author:
roundcube
Message:

Improved error handling in DB connection failure

Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/index.php

    r162 r164  
    33 +-----------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                         | 
    5  | Version 0.1-20060220                                                  | 
     5 | Version 0.1-20060314                                                  | 
    66 |                                                                       | 
    77 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      | 
     
    111111load_gui(); 
    112112 
     113 
     114// check DB connections and exit on failure 
     115if ($err_str = $DB->is_error()) 
     116  { 
     117  raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 
     118                    'message' => $err_str), FALSE, TRUE); 
     119  } 
     120 
     121 
    113122// error steps 
    114123if ($_action=='error' && !empty($_GET['_code'])) 
  • trunk/roundcubemail/program/include/main.inc

    r159 r164  
    7575  $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr']); 
    7676  $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql'; 
     77  $DB->db_connect('w'); 
     78     
    7779 
    7880  // we can use the database for storing session data 
    7981  // session queries do not work with MDB2 
    80   if ($CONFIG['db_backend']!='mdb2' && is_object($DB)) 
     82  if ($CONFIG['db_backend']!='mdb2' && !$DB->is_error()) 
    8183    include_once('include/session.inc'); 
    8284 
  • trunk/roundcubemail/program/include/rcube_db.inc

    r137 r164  
    3636 * @author     David Saez Padros <david@ols.es> 
    3737 * @author     Thomas Bruederli <roundcube@gmail.com> 
    38  * @version    1.16 
     38 * @version    1.17 
    3939 * @link       http://pear.php.net/package/DB 
    4040 */ 
     
    4646  var $db_mode = '';          // Connection mode 
    4747  var $db_handle = 0;         // Connection handle 
     48  var $db_pconn = false;      // Use persistent connections 
     49  var $db_error = false; 
     50  var $db_error_msg = ''; 
    4851 
    4952  var $a_query_results = array('dummy'); 
     
    5760   * @param  string  Optional DSN for read only operations 
    5861   */ 
    59   function __construct($db_dsnw, $db_dsnr='') 
     62  function __construct($db_dsnw, $db_dsnr='', $pconn=false) 
    6063    { 
    6164    if ($db_dsnr=='') 
     
    6467    $this->db_dsnw = $db_dsnw; 
    6568    $this->db_dsnr = $db_dsnr; 
     69    $this->db_pconn = $pconn; 
    6670         
    6771    $dsn_array = DB::parseDSN($db_dsnw); 
     
    7579   * @see  rcube_db::__construct 
    7680   */ 
    77   function rcube_db($db_dsnw,$db_dsnr='') 
    78     { 
    79     $this->__construct($db_dsnw,$db_dsnr); 
     81  function rcube_db($db_dsnw, $db_dsnr='', $pconn=false) 
     82    { 
     83    $this->__construct($db_dsnw, $db_dsnr); 
    8084    } 
    8185 
     
    9195    { 
    9296    // Use persistent connections if available 
    93     $dbh = DB::connect($dsn, array('persistent' => TRUE)); 
     97    $dbh = DB::connect($dsn, array('persistent' => $this->db_pconn)); 
    9498         
    9599    if (DB::isError($dbh)) 
    96100      { 
     101      $this->db_error = TRUE; 
     102      $this->db_error_msg = $dbh->getMessage(); 
     103 
    97104      raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 
    98                         'message' => $dbh->getMessage()), TRUE, FALSE); 
     105                        'message' => $this->db_error_msg), TRUE, FALSE); 
     106                         
     107      return FALSE; 
    99108      } 
    100109 
     
    143152 
    144153    $this->db_handle = $this->dsn_connect($dsn); 
    145     $this->db_connected = true; 
     154    $this->db_connected = $this->db_handle ? TRUE : FALSE; 
     155    } 
     156     
     157     
     158  /** 
     159   * Getter for error state 
     160   * 
     161   * @param  boolean  True on error 
     162   */ 
     163  function is_error() 
     164    { 
     165    return $this->db_error ? $this->db_error_msg : FALSE; 
    146166    } 
    147167 
     
    204224         
    205225    $this->db_connect($mode); 
     226     
     227    if (!$this->db_connected) 
     228      return FALSE; 
    206229 
    207230    if ($this->db_provider == 'sqlite') 
Note: See TracChangeset for help on using the changeset viewer.