Index: includes/database.inc =================================================================== --- includes/database.inc (revision 981) +++ includes/database.inc (working copy) @@ -118,10 +118,12 @@ * @param $name * The name assigned to the newly active database connection. If omitted, the * default connection will be made active. + * @param $abort + * If database connection could not be made, should we abort here or continue. * * @return the name of the previously active database or FALSE if non was found. */ -function db_set_active($name = 'default') { +function db_set_active($name = 'default', $abort = TRUE) { global $db_url, $db_type, $active_db; static $db_conns, $active_name = FALSE; @@ -149,7 +151,27 @@ _db_error_page("The database type '". $db_type ."' is unsupported. Please use either 'mysql' or 'mysqli' for MySQL, or 'pgsql' for PostgreSQL databases."); } - $db_conns[$name] = db_connect($connect_url); + $connection = db_connect($connect_url); + // db_connect is using array return notation. + if (is_array($connection)) { + list($success, $result) = $connection; + // Connection worked + if ($success) { + $db_conns[$name] = $result; + } + // Connection failed and abort page load. + elseif ($abort) { + _db_error_page($result); + } + // Connection failed but return false. Calling function will handle error. + else { + return FALSE; + } + } + // db_connect is not using array return notation; revert to old code style. + else { + $db_conns[$name] = $connection; + } } $previous_name = $active_name; Index: includes/database.mysql.inc =================================================================== --- includes/database.mysql.inc (revision 981) +++ includes/database.mysql.inc (working copy) @@ -77,12 +77,12 @@ $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2); if (!$connection || !mysql_select_db(substr($url['path'], 1))) { // Show error screen otherwise - _db_error_page(mysql_error()); + return array(FALSE, mysql_error()); } // Force UTF-8. mysql_query('SET NAMES "utf8"', $connection); - return $connection; + return array(TRUE, $connection); } /** Index: includes/database.mysqli.inc =================================================================== --- includes/database.mysqli.inc (revision 981) +++ includes/database.mysqli.inc (working copy) @@ -76,13 +76,13 @@ @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS); if (mysqli_connect_errno() > 0) { - _db_error_page(mysqli_connect_error()); + return array(FALSE, mysqli_connect_error()); } // Force UTF-8. mysqli_query($connection, 'SET NAMES "utf8"'); - return $connection; + return array(TRUE, $connection); } /** Index: includes/database.pgsql.inc =================================================================== --- includes/database.pgsql.inc (revision 981) +++ includes/database.pgsql.inc (working copy) @@ -79,14 +79,14 @@ $connection = @pg_connect($conn_string); if (!$connection) { require_once './includes/unicode.inc'; - _db_error_page(decode_entities($php_errormsg)); + return array(FALSE, decode_entities($php_errormsg)); } // Restore error tracking setting ini_set('track_errors', $track_errors_previous); pg_query($connection, "set client_encoding=\"UTF8\""); - return $connection; + return array(TRUE, $connection); } /**