Index: src/wp-includes/class-wpdb.php
===================================================================
--- src/wp-includes/class-wpdb.php	(revision 55346)
+++ src/wp-includes/class-wpdb.php	(working copy)
@@ -2044,7 +2044,7 @@
 					return $this->db_connect( $allow_bail );
 				}
 			}
-		} else {
+		} elseif ( function_exists( 'mysql_connect' ) ) {
 			if ( WP_DEBUG ) {
 				$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
 			} else {
@@ -2053,56 +2053,66 @@
 			}
 		}
 
-		if ( ! $this->dbh && $allow_bail ) {
-			wp_load_translations_early();
+		if ( ! $this->dbh ) {
+			if ( $allow_bail ) {
+				wp_load_translations_early();
 
-			// Load custom DB error template, if present.
-			if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
-				require_once WP_CONTENT_DIR . '/db-error.php';
-				die();
-			}
+				// Load custom DB error template, if present.
+				if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
+					require_once WP_CONTENT_DIR . '/db-error.php';
+					die();
+				}
 
-			$message = '<h1>' . __( 'Error establishing a database connection' ) . "</h1>\n";
+				$message = '<h1>' . __( 'Error establishing a database connection' ) . "</h1>\n";
 
-			$message .= '<p>' . sprintf(
-				/* translators: 1: wp-config.php, 2: Database host. */
-				__( 'This either means that the username and password information in your %1$s file is incorrect or that contact with the database server at %2$s could not be established. This could mean your host&#8217;s database server is down.' ),
-				'<code>wp-config.php</code>',
-				'<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
-			) . "</p>\n";
+				if ( ! function_exists( 'mysqli_connect' ) && ! function_exists( 'mysql_connect' ) ) {
+					$message .= '<p>' . __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) . "</p>\n";
 
-			$message .= "<ul>\n";
-			$message .= '<li>' . __( 'Are you sure you have the correct username and password?' ) . "</li>\n";
-			$message .= '<li>' . __( 'Are you sure you have typed the correct hostname?' ) . "</li>\n";
-			$message .= '<li>' . __( 'Are you sure the database server is running?' ) . "</li>\n";
-			$message .= "</ul>\n";
+					$message .= '<p>' . sprintf(
+						/* translators: %s: mysqli. */
+						__( 'Please check that the %s PHP extension is installed and enabled.' ),
+						'<code>mysqli</code>'
+					) . "</p>\n";
+				} else {
+					$message .= '<p>' . sprintf(
+						/* translators: 1: wp-config.php, 2: Database host. */
+						__( 'This either means that the username and password information in your %1$s file is incorrect or that contact with the database server at %2$s could not be established. This could mean your host&#8217;s database server is down.' ),
+						'<code>wp-config.php</code>',
+						'<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
+					) . "</p>\n";
 
-			$message .= '<p>' . sprintf(
-				/* translators: %s: Support forums URL. */
-				__( 'If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
-				__( 'https://wordpress.org/support/forums/' )
-			) . "</p>\n";
+					$message .= "<ul>\n";
+					$message .= '<li>' . __( 'Are you sure you have the correct username and password?' ) . "</li>\n";
+					$message .= '<li>' . __( 'Are you sure you have typed the correct hostname?' ) . "</li>\n";
+					$message .= '<li>' . __( 'Are you sure the database server is running?' ) . "</li>\n";
+					$message .= "</ul>\n";
+				}
 
-			$this->bail( $message, 'db_connect_fail' );
+				$message .= '<p>' . sprintf(
+						/* translators: %s: Support forums URL. */
+					__( 'If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
+					__( 'https://wordpress.org/support/forums/' )
+				) . "</p>\n";
 
-			return false;
-		} elseif ( $this->dbh ) {
-			if ( ! $this->has_connected ) {
-				$this->init_charset();
+				$this->bail( $message, 'db_connect_fail' );
 			}
 
-			$this->has_connected = true;
+			return false;
+		}
 
-			$this->set_charset( $this->dbh );
+		if ( ! $this->has_connected ) {
+			$this->init_charset();
+		}
 
-			$this->ready = true;
-			$this->set_sql_mode();
-			$this->select( $this->dbname, $this->dbh );
+		$this->has_connected = true;
 
-			return true;
-		}
+		$this->set_charset( $this->dbh );
 
-		return false;
+		$this->ready = true;
+		$this->set_sql_mode();
+		$this->select( $this->dbname, $this->dbh );
+
+		return true;
 	}
 
 	/**
@@ -3900,7 +3910,7 @@
 				} elseif ( mysqli_connect_errno() ) {
 					$error = mysqli_connect_error();
 				}
-			} else {
+			} elseif ( function_exists( 'mysql_error' ) ) {
 				if ( is_resource( $this->dbh ) ) {
 					$error = mysql_error( $this->dbh );
 				} else {
