Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 21466)
+++ wp-includes/wp-db.php	(working copy)
@@ -147,6 +147,16 @@
 	 * @var array
 	 */
 	var $queries;
+	
+	/**
+	 * The number of times to retry reconnecting before dying.
+	 *
+	 * @since 3.5.0
+	 * @access protected
+	 * @see wpdb::check_connection()
+	 * @var int
+	 */
+	protected $reconnect_retries = 5;
 
 	/**
 	 * WordPress table prefix
@@ -1066,6 +1076,48 @@
 	}
 
 	/**
+	 * Check that the connection to the database is still up. If not, try to reconnect.
+	 *
+	 * @since 3.5.0
+	 */
+	function check_connection() {
+		$tries = 1;
+		while ( ! mysql_ping( $this->dbh ) ) {
+			if ( WP_DEBUG ) {
+				$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
+			} else {
+				$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
+			}
+
+			if ( $this->dbh ) {
+				$this->set_charset( $this->dbh );
+				$this->select( $this->dbname, $this->dbh );
+
+				return true;
+			}
+				
+			$tries++;
+			
+			if ( $tries >= $this->reconnect_retries ) {
+				$this->bail( sprintf( __( "
+<h1>Error reconnecting to the database</h1>
+<p>This means that we lost our connection to the database server at <code>%s</code>, your host's database server may be down.</p>
+<ul>
+	<li>Are you sure that the database server is running?</li>
+	<li>Are you sure that the database server is not under particularly heavy load?</li>
+</ul>
+<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p>
+" ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' );
+
+				return false;
+			}
+		}
+		
+		return true;
+	}
+
+
+	/**
 	 * Perform a MySQL database query, using current database connection.
 	 *
 	 * More information can be found on the codex page.
@@ -1079,6 +1131,9 @@
 		if ( ! $this->ready )
 			return false;
 
+		if( ! $this->check_connection() )
+			return false;
+
 		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
 		$query = apply_filters( 'query', $query );
 
