[HyperDB] Multiple Database Setup and Read

Aris Blevins aris at goteama.com
Sat Mar 12 23:39:14 UTC 2011


Hi there,

I have some clients that have a main Wordpress install and now are  
hoping to add two mini-sites that draw specific posts from the main  
site. My hope was to set up two separate Wordpress installs and use  
HyperDB to allow me to pull from the main database as needed.

I have add the databases as follows:

<code>
$wpdb->add_database(array(
	'host'     => 'mysql.german.site',     // If port is other than 3306,  
use host:port.
	'user'     => 'username',
	'password' => 'password',
	'name'     => 'german_db',
	'dataset'  => 'global'
));

$wpdb->add_database(array(
	'host'     => 'mysql.site',     // If port is other than 3306, use  
host:port.
	'user'     => 'username',
	'password' => 'password',
	'name'     => 'main_db',
	'write'    => 0,
	'read'     => 1,
	'dataset'  => 'main'
));
</code>

The first database is for the site that will highlight german content  
from the main site.

The second is the main database - I want to be able to only read from  
this site.

The two databases have different table prefixes (ge_ for german and  
wp_ for the main site)

I had hoped that this would work (as a test):

<code>
global $wpdb;
$wpdb->set_prefix(‘wp_’);

$fivesdrafts = $wpdb->get_results("SELECT post_title FROM $wpdb->posts  
WHERE post_status = 'published'");

foreach ($fivesdrafts as $fivesdraft) {
	echo $fivesdraft->post_title;
}
</code>

But I get nothing on the page here. Any ideas? The final goal here is  
to pull in all published posts from a specific category and list them  
on this page.

Any help would be appreciated, let me know if I need to post more  
information.

Thanks,
Aris


More information about the HyperDB mailing list