[HyperDB] Multiple Database Setup and Read

Callum Macdonald lists.automattic.com at callum-macdonald.com
Mon Mar 14 10:51:23 UTC 2011


Hola Aris,

I don't think HyperDB is the tool for the job you've described.

I think you'd be much simpler to put all the data into one database,
using 2 table prefixes as you suggest, and then pull data through some
kind of plugin.

HyperDB is designed to allow WordPress to scale. Unless you're hosting
thousands of blogs, seeing massive traffic or have some other reason to
split databases over multiple servers, I don't think you need HyperDB.

I suggest you try the support forums for assistance on doing this
through a plugin.

Love & joy - Callum.

On Sat, 2011-03-12 at 15:39 -0800, Aris Blevins wrote:
> 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
> _______________________________________________
> HyperDB mailing list
> HyperDB at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/hyperdb




More information about the HyperDB mailing list