Log in

View Full Version : link in mysql



WAD ELEHEMER
10-16-2012, 08:06 AM
:confused: hi every one can anyone help me in mysql HOW I CAN LINKE BETWEEN 2 DB WITH PHP OR MORE ?

djr33
10-16-2012, 07:37 PM
Your post is unclear. We need more information. What does "link" mean?

In short, you can create two different connections and use them as needed. There is nothing specifically difficult about this.

Another question: why do you want to do this? In most cases, it's probably a bad idea. Sometimes (maybe to move information from one database to another) it might be ok, but not as the main way a website is built, probably.

james438
10-16-2012, 08:31 PM
Somewhat related question: Besides what you mentioned what would be a good reason to maintain two databases? The best I can think of is if a person has a very high traffic forum or has a backup database that is used while the primary one is down for updating or fixing so as to ensure that a website never has any downtime due to updates. That is a little beyond me though. I have a friend in IT that explained the usefulness of a backup database to me and that is how I understand it although it is still a bit beyond me.

WAD ELEHEMER
10-17-2012, 11:54 AM
thunkx

but i was mean like between two table in db with primary key so can we do that between two dbs

bernie1227
10-17-2012, 07:58 PM
Do the tables need to be separate? If so, why? It would be much easier to just put then in the table and use one primary key. Also, please try and use correct English while posting.

traq
10-18-2012, 03:01 AM
like between two table in db with primary key so can we do that between two dbs

keys that link tables to each other are foreign keys, not primary keys.

foreign keys can link 2 or more databases (http://forums.mysql.com/read.php?22,150829,200251#msg-200251), but only when they're on the same host (or virtual host, or you've gone to some extreme effort to connect them).

Although you could mimic the behavior using PHP, it would be complex and wouldn't work nearly as well as a native implementation.

------------------------------------
As james asked, what are you trying to do?

There's probably a better way to do it.

WAD ELEHEMER
10-18-2012, 09:46 AM
Now I understand Thank you bernie1227

and by the way I have a weakness in English, so accept my apologies for the construction errors

WAD ELEHEMER
10-18-2012, 09:54 AM
keys that link tables to each other are foreign keys, not primary keys.

foreign keys can link 2 or more databases (http://forums.mysql.com/read.php?22,150829,200251#msg-200251), but only when they're on the same host (or virtual host, or you've gone to some extreme effort to connect them).

Although you could mimic the behavior using PHP, it would be complex and wouldn't work nearly as well as a native implementation.

------------------------------------
As james asked, what are you trying to do?

There's probably a better way to do it.

I was working at the site and it contains a set of separate databases need to work linking rules in the process of query for admin page far better to work i Chloe in a single database containing the set of tables .

thank you

traq
10-18-2012, 02:30 PM
Specifically:

Are the databases identical (is one a backup for the other, or is it a distributed/ load balanced database), or do the two databases contain different information?

Are the databases on the same host?

If so, are the databases accessible on the same user account?

WAD ELEHEMER
10-19-2012, 01:23 PM
Specifically:

Are the databases identical (is one a backup for the other, or is it a distributed/ load balanced database), or do the two databases contain different information?

Are the databases on the same host?

If so, are the databases accessible on the same user account?

it's not identical and contain different information also on the same host beside accessible on the same user account

traq
10-19-2012, 01:36 PM
Then you should be able to use foreign keys normally, as in the link I showed you. Have you tried it?