Index: wp-db.php
===================================================================
--- wp-db.php	(revision 4079)
+++ wp-db.php	(working copy)
@@ -20,6 +20,10 @@
 	var $last_query;
 	var $col_info;
 	var $queries;
+	var $user;
+	var $password;
+	var $database;
+	var $host;
 
 	// Our tables
 	var $posts;
@@ -37,14 +41,24 @@
 	var $postmeta;
 
 	// ==================================================================
-	//	DB Constructor - connects to the server and selects a database
+	//	DB Constructor - do nothing: lazy load on execution of query
 
 	function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
-		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
+		$this->user = $dbuser;
+		$this->password = $dbpassword;
+		$this->database = $dbname;
+		$this->host = $dbhost;
+	}
+
+	// ==================================================================
+	//	connects to the server and selects a database
+
+	function connect() {
+		$this->dbh = @mysql_connect($this->host, $this->user, $this->password);
 		if (!$this->dbh) {
 			$this->bail("
 <h1>Error establishing a database connection</h1>
-<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p>
+<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$this->host</code>. This could mean your host's database server is down.</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>
@@ -54,13 +68,15 @@
 ");
 		}
 
-		$this->select($dbname);
+		$this->select();
 	}
 
 	// ==================================================================
 	//	Select a DB (if another one needs to be selected)
 
-	function select($db) {
+	function select($db = false) {
+		if ( !$db )
+			$db = $this->database;
 		if (!@mysql_select_db($db, $this->dbh)) {
 			$this->bail("
 <h1>Can&#8217;t select database</h1>
@@ -145,6 +161,10 @@
 		if (SAVEQUERIES)
 			$this->timer_start();
 
+		// Lazy load the database
+		if ( !$this->dbh )
+			$this->connect();
+
 		$this->result = @mysql_query($query, $this->dbh);
 		++$this->num_queries;
 
@@ -364,4 +384,4 @@
 }
 
 $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
-?>
\ No newline at end of file
+?>
