summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2005-07-27 01:58:43 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2005-07-27 01:58:43 +0000
commitd9d4b9bdab8ac4b6e5c01926da9d5a084707be94 (patch)
tree26d7809ceada308162d639ebf78c498d1e3955aa /includes
parent88ccaf02c404878c21288f9d00f594b62962b610 (diff)
downloadbrdo-d9d4b9bdab8ac4b6e5c01926da9d5a084707be94.tar.gz
brdo-d9d4b9bdab8ac4b6e5c01926da9d5a084707be94.tar.bz2
- #27231: Friendly DB error screens.
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc18
-rw-r--r--includes/common.inc4
-rw-r--r--includes/database.inc6
-rw-r--r--includes/database.mysql.inc31
-rw-r--r--includes/database.pgsql.inc27
-rw-r--r--includes/theme.inc27
-rw-r--r--includes/unicode.inc11
7 files changed, 114 insertions, 10 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index fe85eb447..8354520e6 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -864,4 +864,20 @@ function _drupal_bootstrap($phase) {
}
}
-?>
+/**
+ * Enables use of the theme system without requiring database access. Since
+ * there is not database access no theme will be enabled and the default
+ * themable fuctions will be called. Some themable functions can not be used
+ * without the full Drupal API loaded. For example, theme_page() is
+ * unavailable and theme_maintenance_page() must be used in its place.
+ */
+function drupal_maintenance_theme() {
+ global $theme;
+ require_once './includes/theme.inc';
+ require_once './includes/common.inc';
+ require_once './includes/unicode.inc';
+ unicode_check();
+ $theme = '';
+}
+
+?> \ No newline at end of file
diff --git a/includes/common.inc b/includes/common.inc
index 93724afd6..2672bf895 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1831,7 +1831,7 @@ function drupal_implode_autocomplete($array) {
function _drupal_bootstrap_full() {
static $called;
- global $locale, $multibyte;
+ global $locale;
if ($called) {
return;
@@ -1850,7 +1850,7 @@ function _drupal_bootstrap_full() {
// Emit the correct charset HTTP header.
drupal_set_header('Content-Type: text/html; charset=utf-8');
// Detect string handling method
- $multibyte = unicode_check();
+ unicode_check();
// Initialize $_GET['q'] prior to loading modules and invoking hook_init().
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
diff --git a/includes/database.inc b/includes/database.inc
index c76b0083d..fa111b460 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -116,7 +116,11 @@ function db_set_active($name = 'default') {
include_once($handler);
}
else {
- die('Unsupported database type');
+ drupal_maintenance_theme();
+ drupal_set_title('Unsupported database type');
+ print theme('maintenance_page', '<p>The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either <var>mysql</var> for MySQL databases or <var>pgsql</var> for PostgreSQL databases. The database information is in your <code>settings.php</code> file.</p>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+ exit;
}
$db_conns[$name] = db_connect($connect_url);
diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc
index 78bd24656..22012d432 100644
--- a/includes/database.mysql.inc
+++ b/includes/database.mysql.inc
@@ -34,9 +34,36 @@ function db_connect($url) {
// server.
// - 2 means CLIENT_FOUND_ROWS: return the number of found
// (matched) rows, not the number of affected rows.
- $connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2) or die(mysql_error());
+ $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
+ if (!$connection) {
+ drupal_maintenance_theme();
+ drupal_set_title('Unable to connect to database server');
+ print theme('maintenance_page', '<p>This either means that the username and password information in your <code>settings.php</code> file is incorrect or we can\'t contact the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
+<p>The MySQL error was: '. theme('placeholder', mysql_error()) .'.</p>
+<p>Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
+<ul>
+ <li>Are you sure you have the correct username and password?</li>
+ <li>Are you sure that you have typed the correct hostname?</li>
+ <li>Are you sure that the database server is running?</li>
+</ul>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+ exit;
+ }
- mysql_select_db(substr($url['path'], 1)) or die('unable to select database');
+ if (!mysql_select_db(substr($url['path'], 1))) {
+ drupal_maintenance_theme();
+ drupal_set_title('Unable to select database');
+ print theme('maintenance_page', '<p>We were able to connect to the MySQL database server (which means your username and password is okay) but not able to select the database.</p>
+<p>The MySQL error was: '. theme('placeholder', mysql_error()) .'.</p>
+<p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .'. The username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
+<ul>
+ <li>Are you sure you have the correct database name?</li>
+ <li>Are you sure the database exists?</li>
+ <li>Are you sure the username has permission to access the database?</li>
+</ul>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+ exit;
+ }
return $connection;
}
diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc
index 9e4ecf21b..46acbe14a 100644
--- a/includes/database.pgsql.inc
+++ b/includes/database.pgsql.inc
@@ -25,7 +25,32 @@ function db_connect($url) {
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
$conn_string .= isset($url['port']) ? ' port=' . $url['port'] : '';
- $connection = pg_connect($conn_string) or die(pg_last_error());
+
+ // pg_last_error() does not return a useful error message for database
+ // connection errors. We must turn on error tracking to get at a good error
+ // message, which will be stored in $php_errormsg.
+ $track_errors_previous = ini_get('track_errors');
+ ini_set('track_errors', 1);
+
+ $connection = @pg_connect($conn_string);
+ if (!$connection) {
+ drupal_maintenance_theme();
+ drupal_set_title('Unable to connect to database');
+ print theme('maintenance_page', '<p>This either means that the database information in your <code>settings.php</code> file is incorrect or we can\'t contact the PostgreSQL database server. This could mean your hosting provider\'s database server is down.</p>
+<p>The PostgreSQL error was: '. theme('placeholder', decode_entities($php_errormsg)) .'</p>
+<p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .', the username is '. theme('placeholder', $url['user']) .', and the database server is '. theme('placeholder', $url['host']) .'.</p>
+<ul>
+ <li>Are you sure you have the correct username and password?</li>
+ <li>Are you sure that you have typed the correct hostname?</li>
+ <li>Are you sure you have the correct database name?</li>
+ <li>Are you sure that the database server is running?</li>
+</ul>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+ exit;
+ }
+
+ // Restore error tracking setting
+ ini_set('track_errors', $track_errors_previous);
return $connection;
}
diff --git a/includes/theme.inc b/includes/theme.inc
index 02f74fd36..04100a8e9 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -160,7 +160,7 @@ function list_theme_engines($refresh = FALSE) {
function theme() {
global $theme, $theme_engine;
- if (!$theme) {
+ if ($theme === NULL) {
// Initialize the enabled theme.
$theme = init_theme();
}
@@ -440,6 +440,31 @@ function theme_page($content) {
return $output;
}
+function theme_maintenance_page($content) {
+ drupal_set_header('Content-Type: text/html; charset=utf-8');
+ theme('add_style', 'misc/drupal.css');
+ theme('add_style', 'misc/maintenance.css');
+ $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
+ $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
+ $output .= '<head>';
+ $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
+ $output .= ' <title>'. drupal_get_title() .'</title>';
+ $output .= theme_get_styles();
+ $output .= '</head>';
+ $output .= '<body>';
+ $output .= '<h1>' . drupal_get_title() . '</h1>';
+
+ $output .= theme('status_messages');
+
+ $output .= "\n<!-- begin content -->\n";
+ $output .= $content;
+ $output .= "\n<!-- end content -->\n";
+
+ $output .= '</body></html>';
+
+ return $output;
+}
+
/**
* Returns themed set of status and/or error messages. The messages are grouped
* by type.
diff --git a/includes/unicode.inc b/includes/unicode.inc
index 368bc8596..6acc41411 100644
--- a/includes/unicode.inc
+++ b/includes/unicode.inc
@@ -6,6 +6,13 @@ define('UNICODE_SINGLEBYTE', 0);
define('UNICODE_MULTIBYTE', 1);
/**
+ * Wrapper around _unicode_check().
+ */
+function unicode_check() {
+ $GLOBALS['multibyte'] = _unicode_check();
+}
+
+/**
* Perform checks about Unicode support in PHP, and set the right settings if
* needed.
*
@@ -16,7 +23,7 @@ define('UNICODE_MULTIBYTE', 1);
* @param $errors
* Whether to report any fatal errors with form_set_error().
*/
-function unicode_check($errors = false) {
+function _unicode_check($errors = false) {
// Set the standard C locale to ensure consistent, ASCII-only string handling.
setlocale(LC_CTYPE, 'C');
@@ -70,7 +77,7 @@ function unicode_check($errors = false) {
* Return the required Unicode status and errors for admin/settings.
*/
function unicode_settings() {
- $status = unicode_check(true);
+ $status = _unicode_check(true);
$options = array(UNICODE_SINGLEBYTE => t('Standard PHP: operations on Unicode strings are emulated on a best-effort basis. Install the <a href="%url">PHP mbstring extension</a> for improved Unicode support.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
UNICODE_MULTIBYTE => t('Multi-byte: operations on Unicode strings are supported through the <a href="%url">PHP mbstring extension</a>.', array('%url' => 'http://www.php.net/manual/nl/ref.mbstring.php')),
UNICODE_ERROR => t('Invalid: the current configuration is incompatible with Drupal.'));