Forum Moderators: coopster

Message Too Old, No Replies

Combine results from 2 DBs

Merge into array via PHP?

         

surfgatinho

5:30 pm on May 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to figure the best way to combine the results from 2 different DBs on 2 different servers.
I'd use a union if they were in the same DB but I'm thinking the way to go is to match up the column names and then merge the results together into a standard array.

So a)Is this the best way to go about it and b) what's the best way to do it?

Any help would be appreciated.

Thanks,
Chris

LifeinAsia

5:58 pm on May 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It depends on the DB you're using. With MS SQL you can setup a linked server, which would allow you to use UNION like usual. You'd just have to fully qualify the table on the linked server. Instead of TableName, you'd need to specify something like [LinkedServerName].DatabaseName.[dbo].TableName

[edited by: LifeinAsia at 5:58 pm (utc) on May 13, 2009]

surfgatinho

6:02 pm on May 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, should have said. I'm running MySQL

LifeinAsia

6:56 pm on May 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



No idea if you can do that in MySQL.

Alternatively, maybe you can do something where one server automatically replicates the data to the other server?

Otherwise, it's probably easier to just "unionize" the data on the PHP side.

coopster

7:13 pm on May 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could always set up a script on the remote server that sends the formatted data to you or perhaps pull it from the local server. comma-separated value, tab-separated, xml, etc.