summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2005-07-27 16:15:29 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2005-07-27 16:15:29 +0000
commit90c586422da74ef4e56bc93c2b16aeab22bc613f (patch)
tree77c67013aba3cd2227cf9dc3a3e1a77555a72580
parentcc428420cc487facf6548355e826683e2c8a6e02 (diff)
downloadwordpress-mu-90c586422da74ef4e56bc93c2b16aeab22bc613f.tar.gz
wordpress-mu-90c586422da74ef4e56bc93c2b16aeab22bc613f.tar.xz
wordpress-mu-90c586422da74ef4e56bc93c2b16aeab22bc613f.zip
Use multiple databases.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@80 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r--wp-inst/wp-config-sample.php43
-rw-r--r--wp-inst/wp-includes/wp-db.php51
-rw-r--r--wp-inst/wp-settings.php34
3 files changed, 126 insertions, 2 deletions
diff --git a/wp-inst/wp-config-sample.php b/wp-inst/wp-config-sample.php
index 6ceb2da..32f9276 100644
--- a/wp-inst/wp-config-sample.php
+++ b/wp-inst/wp-config-sample.php
@@ -16,6 +16,49 @@ $table_prefix = 'wp_'; // example: 'wp_' or 'b2' or 'mylogin_'
// to enable German language support.
define ('WPLANG', '');
+define( "WP_USE_MULTIPLE_DB", false );
+$db_list = array(
+ "write" => array(
+ array( "db_name" => "WRITE_DB_NAME1",
+ "db_user" => "WRITE_DB_USER1",
+ "db_password" => "WRITE_DB_PASS1",
+ "db_host" => "WRITE_DB_HOST1"
+ )
+ ),
+ "read" => array(
+ array( "db_name" => "READ_DB_NAME1",
+ "db_user" => "READ_DB_USER1",
+ "db_password" => "READ_DB_PASS1",
+ "db_host" => "READ_DB_HOST1"
+ ),
+ array( "db_name" => "READ_DB_NAME2",
+ "db_user" => "READ_DB_USER2",
+ "db_password" => "READ_DB_PASS2",
+ "db_host" => "READ_DB_HOST2"
+ ),
+ array( "db_name" => "READ_DB_NAME3",
+ "db_user" => "READ_DB_USER3",
+ "db_password" => "READ_DB_PASS3",
+ "db_host" => "READ_DB_HOST3"
+ ),
+ array( "db_name" => "READ_DB_NAME4",
+ "db_user" => "READ_DB_USER4",
+ "db_password" => "READ_DB_PASS4",
+ "db_host" => "READ_DB_HOST4"
+ ),
+ array( "db_name" => "READ_DB_NAME5",
+ "db_user" => "READ_DB_USER5",
+ "db_password" => "READ_DB_PASS5",
+ "db_host" => "READ_DB_HOST5"
+ ),
+ array( "db_name" => "READ_DB_NAME6",
+ "db_user" => "READ_DB_USER6",
+ "db_password" => "READ_DB_PASS6",
+ "db_host" => "READ_DB_HOST6"
+ )
+ )
+ );
+
/* Stop editing */
define('ABSPATH', dirname(__FILE__).'/');
diff --git a/wp-inst/wp-includes/wp-db.php b/wp-inst/wp-includes/wp-db.php
index 73d4be7..765b0c0 100644
--- a/wp-inst/wp-includes/wp-db.php
+++ b/wp-inst/wp-includes/wp-db.php
@@ -53,6 +53,10 @@ class wpdb {
<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>
");
}
+ $this->db_host = $dbhost;
+ $this->db_user = $dbuser;
+ $this->db_password = $dbpass;
+ $this->db_name = $dbname;
$this->select($dbname);
}
@@ -124,6 +128,48 @@ class wpdb {
$this->last_query = null;
}
+ function db_connect( $query ) {
+ global $db_list;
+ if( is_array( $db_list ) == false )
+ return true;
+
+ if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {
+ $details = $db_list[ 'write' ][ mt_rand( 0, count( $db_list[ 'write' ] ) -1 ) ];
+ } else {
+ $details = $db_list[ 'read' ][ mt_rand( 0, count( $db_list[ 'read' ] ) -1 ) ];
+ }
+
+ if( $this->db_host != $details[ 'db_host' ] || $this->db_user != $details[ 'db_user' ] || $this->db_password != $details[ 'db_password' ] ) {
+ if ($this->dbh) {
+ @mysql_close( $this->dbh );
+ }
+ $this->db_host = $details[ 'db_host' ];
+ $this->db_user = $details[ 'db_user' ];
+ $this->db_password = $details[ 'db_password' ];
+
+ $this->dbh = @mysql_connect( $details[ 'db_host' ], $details[ 'db_user' ], $details[ 'db_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>
+<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>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>
+");
+ }
+ $this->db_name = $details[ 'db_name' ];
+ $this->select( $details[ 'db_name' ] );
+ }
+
+ if( $this->db_name != $details[ 'db_name' ] ) {
+ $this->db_name = $details[ 'db_name' ];
+ $this->select( $details[ 'db_name' ] );
+ }
+ }
+
// ==================================================================
// Basic Query - see docs for more detail
@@ -142,6 +188,9 @@ class wpdb {
if (SAVEQUERIES)
$this->timer_start();
+ if( defined( "WP_USE_MULTIPLE_DB" ) && CONSTANT( "WP_USE_MULTIPLE_DB" ) == true )
+ $this->db_connect( $query );
+
$this->result = @mysql_query($query, $this->dbh);
++$this->num_queries;
@@ -359,4 +408,4 @@ HEAD;
}
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
-?> \ No newline at end of file
+?>
diff --git a/wp-inst/wp-settings.php b/wp-inst/wp-settings.php
index 5cc3d63..7e51374 100644
--- a/wp-inst/wp-settings.php
+++ b/wp-inst/wp-settings.php
@@ -52,12 +52,38 @@ $domain = $_SERVER['HTTP_HOST'];
if( substr( $domain, 0, 4 ) == 'www.' )
$domain = substr( $domain, 4 );
+function is_installed() {
+ global $wpdb, $domain, $base;
+ $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
+ if( $check == false ) {
+ $msg = '<strong>Database Tables Missing.</strong><br /> The table <em>' . DB_NAME . '::' . $wpdb->site . '</em> is missing. Delete the .htaccess file and run the installer again!<br />';
+ } else {
+ $msg = '<strong>Could Not Find Blog!</strong><br />';
+ $msg .= "Searched for <em>" . $domain . $base . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />";
+ }
+ $msg .= "Please check that your database contains the following tables:<ul>
+ <li> $wpdb->blogs </li>
+ <li> $wpdb->users </li>
+ <li> $wpdb->usermeta </li>
+ <li> $wpdb->site </li>
+ <li> $wpdb->sitemeta </li>
+ <li> $wpdb->sitecategories </li>
+ </ul>";
+ $msg .= "If you suspect a problem please report it to <a href='http://mu.wordpress.org/forums/'>support forums</a>!";
+ die( "<h1>Fatal Error</h1> " . $msg );
+}
$current_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain = '$domain' AND path = '$base'");
+if( $current_blog == false ) {
+ is_installed();
+}
$blog_id = $current_blog->blog_id;
$is_public = $current_blog->is_public;
$site_id = $current_blog->site_id;
$current_site = $wpdb->get_row("SELECT * FROM $wpdb->site WHERE id='$site_id'");
+if( $current_site == false ) {
+ is_installed();
+}
if( $current_site->domain == $domain && $current_site->path == $base ) {
$wpblog = 'main';
}
@@ -76,7 +102,13 @@ if( $blog_id == false ) {
$blog_id = 1;
}
} else {
- die( "No Blog by that name on this system." );
+ $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" );
+ if( $check == false ) {
+ $msg = ': DB Tables Missing';
+ } else {
+ $msg = '';
+ }
+ die( "No Blog by that name on this system." . $msg );
}
}