Forum Moderators: coopster

Message Too Old, No Replies

query in multiple DB

         

PHPycho

10:23 am on Jan 13, 2010 (gmt 0)

10+ Year Member



Suppose i have three dbs on the same server.
DB #1:
host: localhost
user: root1
pass: pass1
Db: db1

DB #2:

host: localhost
user: root2
pass: pass2
Db: db2

DB #3:

host: localhost
user: root3
pass: pass3
Db: db3

You have noticed from above that i have three DBs on the same server but have different users.

Summary of DBs
DB #1 is use for main login page.
DB #2 has table called products2

products2
--------
id
sku
name
...

DB #3 has table called products3
products3
---------
id
sku
name
....

What i want to do is:
I want perform query in DB #2's products2 table & DB #3's products3 so that i can display the products with common sku.
Hope my problem is clear.

My Question is:
1> is it possible to make a single query for two database? If yes how?
2> if above is not possible then,
Would it be effective to make separate fetching from two dbs as an arrays.
And manipulating that array for the required results?

Thanks

omoutop

12:11 pm on Jan 13, 2010 (gmt 0)

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



3 databases equals 3 users
If one user has enough priviledges to access all 3 databses then you can query multiple db

Search for 'grant privileges' in the mysql manual to see how to do this.

Assuming all went well....
SELECT a.field 1, b.field2 FROM table1 a, table2 b WHERE a.field4=b.field5

The above is a small example of the syntax to use
i just dont like JOINS and use that syntax:)