PDA

View Full Version : database linking and table linking


patriotcow
01-28-2005, 10:57 AM
Ok I have this task that I want to do for 2 of my forums and maybe more in the future.
I would like to link tables from databases that are in seperate databases from each other.

E.g:

I have a database named vbulletin1 and in vbulletin1 there is a table called vb_users. Then I have a database named vbulletin2 and there is a table called vb_users. How would I link the 2 vb_users together so that on both forums the users are updated on both if you get me?

Thanks

Dean C
01-28-2005, 11:05 AM
This has been asked several times and as it stands it's a pretty major undertaking :) There's no easy way to do it.

patriotcow
01-28-2005, 11:19 AM
The best method would be in phpmyadmin?

Andreas
01-28-2005, 11:49 AM
You can't.
Having x installations share a common user base requires almost all vBulletin PHP files to be modified.

Marco van Herwaarden
01-28-2005, 12:12 PM
Just think of all the duplicate userid's for example, then you will understand this is not something that can easily be done

Dean C
01-28-2005, 01:01 PM
It could be done via the database class if vBulletin used aliases on all table names it would be possible to do it internally (in theory) with a few reg exps in the db class :)

Dean C
01-28-2005, 01:56 PM
Something interesting to think about:

$dbprefix = 'newdb';
$string = "SELECT * FROM user AS user WHERE userid='moo'";
$pattern = '/(.*)FROM[\s\n\r]+([A-Za-z]+)[\s\n\r]+AS[\s\n\r]+(\\2)(.*)/';
if(preg_match($pattern, $string, $array))
{
print_r($array);
$nstring = preg_replace($pattern, "$1 FROM $dbprefix.$2 AS $3 $4", $string);
echo '<br />' . $nstring;
}


Now thinking about it, if we did the same for INSERT, UPDATE, REPLACE INTO and DELETE we could be on to something as it seems the devs have introduced aliases to all tables since the first gold release :)

patriotcow
01-28-2005, 09:07 PM
Ahh that looks like somthing :nervous: Trouble is I am no expert on hacks :disappointed:

Dean C
01-28-2005, 09:14 PM
I did it earlier, it works. But usergroup and forum permissions are big issues which require too much code editing to even think about :)

patriotcow
01-28-2005, 09:40 PM
You should tell me how so I can work on it more I might pay somone...but wouldn't mind a bit of knoledge on what youve done so far :nervous: