roundcubemail/program/lib/Roundcube/rcube_db.php
public function db_connect($mode, $force = false)
    {
        // previous connection failed, don't attempt to connect again
        if ($this->conn_failure) {
            return;
        }

        // no replication
        if ($this->db_dsnw == $this->db_dsnr) {
            $mode = 'w';
        }

        // Already connected
        if ($this->db_connected) {
            // connected to db with the same or "higher" mode (if allowed)
            if ($this->db_mode == $mode || $this->db_mode == 'w' && !$force && !$this->options['dsnw_noread']) {
                return;
            }
        }

        $dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array;
        $this->dsn_connect($dsn, $mode);

        // use write-master when read-only fails
        if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) {
            $this->dsn_connect($this->db_dsnw_array, 'w');
        }

        $this->conn_failure = !$this->db_connected;
    }
public function db_connect($mode, $force = false)
    {
        // previous connection failed, don't attempt to connect again
        if ($this->conn_failure) {
            return;
        }

        // no replication
        if ($this->db_dsnw == $this->db_dsnr) {
            $mode = 'w';
        }

        // Already connected
        if ($this->db_connected) {
            // connected to db with the same or "higher" mode (if allowed)
            if ($this->db_mode == $mode || $this->db_mode == 'w' && !$force && !$this->options['dsnw_noread']) {
                return;
            }
        }

        $dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array;
        $this->dsn_connect($dsn, $mode);

        // use write-master when read-only fails
        if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) {
            $this->dsn_connect($this->db_dsnw_array, 'w');
        }

        $this->conn_failure = !$this->db_connected;
    }
public function db_connect ( $ mode , $ force = false ) { // previous connection failed, don't attempt to connect again if ( $ this -> conn_failure ) { return ; } // no replication if ( $ this -> db_dsnw == $ this -> db_dsnr ) { $ mode = 'w' ; } // Already connected if ( $ this -> db_connected ) { // connected to db with the same or "higher" mode (if allowed) if ( $ this -> db_mode == $ mode || $ this -> db_mode == 'w' && ! $ force && ! $ this -> options [ 'dsnw_noread' ] ) { return ; } } $ dsn = ( $ mode == 'r' ) ? $ this -> db_dsnr_array : $ this -> db_dsnw_array ; $ this -> dsn_connect ( $ dsn , $ mode ) ; // use write-master when read-only fails if ( ! $ this -> db_connected && $ mode == 'r' && $ this -> is_replicated ( ) ) { $ this -> dsn_connect ( $ this -> db_dsnw_array , 'w' ) ; } $ this -> conn_failure = ! $ this -> db_connected ; }
Connect to appropriate database depending on the operation

@param string  $mode  Connection mode (r|w)
@param boolean $force Enforce using the given mode
Connect to appropriate database depending on the operation