Changeset 423 for branches/1.1dev/config


Ignore:
Timestamp:
Aug 13, 2013 11:52:52 PM (11 years ago)
Author:
anonymous
Message:

Backporting fixes to v1.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/config/boot.inc.php

    r352 r423  
    7676   
    7777    // Connect to MySQL
    78     $dbh = mysql_connect('localhost', $CFG->username, $CFG->password);
    79    
    80     // Select database
    81     mysql_select_db($CFG->database, $dbh);
     78    if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) {
     79        // Select database
     80        mysql_select_db($CFG->database, $dbh);       
     81    }
    8282
    8383    // Connection errors.
     
    109109            echo "<!-- --------------------------------------\n" . $debugqry . "\n-->";
    110110        }
     111       
     112        // Ensure we have an active connection.
     113        // If we continue on a dead connection we might experience a "MySQL server has gone away" error.
     114        // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
     115        // Unfortunately we'll have redundant code with the reconnection below.
     116        if (!mysql_ping($dbh)) {
     117            logMsg(sprintf('MySQL ping failed; reconnecting
 ("%s")', truncate(trim($debugqry), 150)), LOG_NOTICE, __FILE__, __LINE__);
     118            mysql_close($dbh);
     119            if ($dbh = mysql_connect('localhost', $CFG->username, $CFG->password)) {
     120                mysql_select_db($CFG->database, $dbh);       
     121            }
     122            if (!$dbh || mysql_error($dbh)) {
     123                $mysql_error_msg = $dbh ? 'Codebase MySQL error: (' . mysql_errno($dbh) . ') ' . mysql_error($dbh) : 'Codebase MySQL error: Could not connect to server.';
     124                if ($CFG->db_debug) {
     125                    echo $mysql_error_msg . "\n";
     126                } else {
     127                    echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
     128                }
     129                logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
     130                die;
     131            }
     132        }
     133
    111134        $qid = mysql_query($query, $dbh);
    112135        if (!$qid || mysql_error($dbh)) {
Note: See TracChangeset for help on using the changeset viewer.