2 Sites, 1 DB, Possible?
-
If I install WP into two folders, each linked to a different webaddress, but both point to a single DB, will they function OK? I’m guessing not since the site URL and blog URL are stored in the database, as is the currently selected template/theme.
Is there a way to trick WP, so that the URL and the theme settings can be hardcoded in the wp-config.php file?
Or is that simply asking too much of WP? If it isn’t possible, that’s OK, it’s not the end of the world. Just wondering.
Tg
-
Yup, it’s easy. In each site’s “wpconfig.php” file, set the table prefix to some unique value, other than the default “wp_” value. Then both (or all 10 in my case) blogs can use the same database, but remain completely independent from each other. So one blog might use “blog1_” as a prefix, the other would use “blog2_” for the prefix. Capiche?
There is also a multi-user version of WordPress being developed at https://mu.www.remarpro.com (I think that’s the addy) that might cover your needs as well, but I don’t know what it’s status is.
I forgot to mention that it would be the same content on both sites…. so having a different table prefix wouldn’t work. I don’t want them to be independant of each other.
Tg
Gotcha.
It’s easy enough to point two domains to the same WP install, right up until a link is clicked. Then the address would revert to whatever domain is set in the DB.
The other way would be to use Javascript and the DOM. A plugin could be written to insert a script that captures MouseDown events (or just modify the “header.php” page manually in 1.5, or “index.php” in 1.2x). If the event is fired on a link, the script would check for the domain name that exists in the WP database. If it matches, it would replace that domain with the other one. The operation would be transparent to the user, except that the address that shows in the status bar would be to whatever domain was in the DB – unless the Javascript also captured MouseOver events and set the statusbar itself with the replacement domain. In either case, the address bar at the top would show whatever domain name the user used to access the site.
And before anyone says it can’t be done, I’ve done things very similar (but not for a while). It should work in any DOM-compliant browser that has Javascript enabled. My script simply attached a querystring with the current session ID to any link that was local to the site. I doubt I still have a copy anywhere (this was a couple years ago), but I remember the technique.
i really want to install wp on two different sites and use the same database- with the same content on each site. and yes the above mentioned problems shall exist, but i dont know how to encode the DOM thingy…. is there any workaround possible. and yes the idea of hardcoding the blog address into the wp-config file is good but its upto the developers to see into it.
Do as RustIndy says above, but edit each sites wp-settings.php around line 40 or so, you’ll see the references for each table name. You can hard code those so that they both point to the same tables for everything except the options table. If you want each site to have its own users, both sites will have to have their own users table, comments table, and post2cat table.
okie i guess u mean this area
// Table names
$wpdb->posts = $table_prefix . ‘posts’;
$wpdb->users = $table_prefix . ‘users’;
$wpdb->categories = $table_prefix . ‘categories’;
$wpdb->post2cat = $table_prefix . ‘post2cat’;
$wpdb->comments = $table_prefix . ‘comments’;
$wpdb->links = $table_prefix . ‘links’;
$wpdb->linkcategories = $table_prefix . ‘linkcategories’;
$wpdb->options = $table_prefix . ‘options’;
$wpdb->postmeta = $table_prefix . ‘postmeta’;i guess wp-db->options table contains the address of the blog for each of the two sites.
now what I need is that the $wp-db->options table is referenced locally and all other tables are looked up from a remote location….
now for this I guess we shall have to define two usernames and passwords, one for the local sql database and one for the remote database, and then we have to create two connection objects etc.
i dont know any php, but can you gimme a hint as to how I can hardcode the tables- then I shall try to work out a solution.macmanx the codex reference addresses the issue of having many blogs on the same installation, on the same database, but we want to create the same blog on many sites..
We want two different installations of wordpress running on two different servers should share the same database. The weblog running on two different websites should be same, reading data from a common database- so basically we need that all tables are shared except the options table
the options table should not be shared as this table contains the address of the blog, so this table must be looked up locally, as the address of both the blogs shall be differentnow it gets interesting
look at the file /wp-includes/wp-db.php
it defines the wpdb class asclass wpdb {
var $show_errors = true;
var $num_queries = 0;
var $last_query;
var $col_info;
var $queries;// Our tables
var $posts;
var $users;
var $categories;
var $post2cat;
var $comments;
var $links;
var $linkcategories;
var $options;
var $optiontypes;
var $optionvalues;
var $optiongroups;
var $optiongroup_options;
var $postmeta;// ==================================================================
// DB Constructor – connects to the server and selects a databasefunction wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
..
..
..
..and in the last line we have the entire object being equated with the connection
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
now what we need to do is that only for the member $wpdb.$options needs to be equated with a new connection to the localhost server while we globally define the $host variable to be on a remote server from which the database has to be picked up
either we create a new class “$test” with only one member $options and then we connect the object of this class to the local server while we let the database connectionfor $wpdb object be with the remote server. and then we equate the $ options member eg. $wpdb.$options = = $test.$options
would that work? can class members be directly equated in php? can somebody with a thorough knowledge please help?Can you put both options tables in the same database? Just change the prefix on one (or both) As RustIndy said “In each site’s “wpconfig.php” file, set the table prefix to some unique value, other than the default “wp_” value.” If you hard code the other tables, this prefix will only be read when accessing the options table.
For example your database would have the following tables:
posts
users
categories
post2cat
comments
links
linkcategories
postmeta
blog1_options
blog1_optionsthen in blog1 wpconfig.php (line 9ish) you would have:
$table_prefix = ‘blog1_’;and in blog 2 wpconfig.php you would have:
$table_prefix = ‘blog2_’;and both wp-settings.php would have:
$wpdb->posts = ‘posts’;
$wpdb->users = ‘users’;
$wpdb->categories = ‘categories’;
$wpdb->post2cat = ‘post2cat’;
$wpdb->comments = ‘comments’;
$wpdb->links = ‘links’;
$wpdb->linkcategories = ‘linkcategories’;
$wpdb->options = $table_prefix . ‘options’;
$wpdb->postmeta = ‘postmeta’;Note the only table using $table_prefix is the options table.
I’m currently running a similar setup on my site (https://www.plogress.com) with over 500 blogs. The only common tables are the user table and categories table. Unfortunately, the database has over 2,000 tables! I’m now hacking everything to share all of the same tables and use a blog id to separate each blogs data. Once it’s running properly and tested, I’ll make a seperate post here to describe it in more detail.
Hope this helps (exept that last paragraph, I don’t recommend trying that one at home)
that again comes back to the same point, actually what we need to do here is we need to reference tables like:
$wpdb->options = LOCALHOST.’options’;
$wpdb->posts = REMOTEHOST.’posts’;
$wpdb->users = REMOTEHOST.’users’;
$wpdb->categories = REMOTEHOST.’categories’;
$wpdb->post2cat = REMOTEHOST.’post2cat’;
$wpdb->comments = REMOTEHOST.’comments’;
$wpdb->links = REMOTEHOST.’links’;
$wpdb->linkcategories = REMOTEHOST.’linkcategories’;
$wpdb->postmeta = REMOTEHOST.’postmeta’;Actually what we need to do {the basic problem}, is to retrieve the options from a localhost sql server while we retrieve the rest of the tables from a database located at a remote host sql server
that way we can have the same blog at two different URL’s, {the options table stores the URL of the blog, so only the options table needs to be different}the method u described shall enable multiple blogs within the same database on the same MySQL server, but the problem here is that
1) There are two separate websites running on two different servers
2) both websites run a separate MySQL server with different address
3) we need the same blog on both websitesso we designed
website1: picks up the database from the MySQL server of website1website2: picks up the database EXCEPT the OPTIONS table from sql server of website1, and also picks up the options table from the sql server of website2
because the options table stores the blog URL, so it needs to be different for both sites.
MY GOD, THIS IS GETTING VERY CONFUZING!!!!!
Right, but there is no need to have the options table locally, it will work just as well on the remote database (so long as the prefix is different), then we avoid any problems with managing different connections (connections to multiple databases might be easier than I’m assuming, I haven’t tried it) If blog2 can access the database on blog1 machine for the post and comment data, it can read the blog2_options table from there as well(assuming appropriate permissions).
If we really want connections to two databases. I believe we have to go to wp-db.php and add a new function wpdb2 that will make a connection to the new database, and make sure it gets initialized along with wpdb. We would then have to change references to wpdb to wpdb2 where applicable, test it, find out it doesn’t work, and go back through and see what we forgot!
okie, i got ur point, brentrv.
its been an interesting discussion we had here. i’ll do this and shall get back to this thread, please do bookmark this place and watch it for a couple of days
thanks……
* but what about cross references? if other tables refer to the options table then? the name of the options table is different for both the cases, but the rest of the tables are common, so the resto of the tables shall refer to the options table by only one name even though we might add another options table under a different name
EDIT: i guess there wont be any cross references for the options table, otherwise you would have faced problems running those 500 blogs. thanks for the insight, now I shall try it out, I shall most probably get a new domain in a day or two, and then I shall run a common blog on both my domains.2 Sites, 1 DB, Possible?
POSSIBLE
Thanks bretrv, It was a great idea, and it really works.
see:
https://www.anat [dot] uni [dot] cc
https://www.anat [dot] moved [dot] in{had to post the website address as such to avoid those spam bots}
these are two sites, running from the same database, they are absolutely identical, however they are different. Pinging both produces different IP addresses. Both reference the same tables from the same database, but however only the options table has been copied into two tables such that both sites can function independently, but rest of the tables are same so that the content is identical. The method is what has been descibed above. If there is any confusion then feel free to contact me. The description given in the above posts is sufficient and self explanatory.
- The topic ‘2 Sites, 1 DB, Possible?’ is closed to new replies.