vinpkl — 2010-04-16T01:49:25-04:00 — #1
i want to use and connect two databases together.
i m connecting first database file "config.php" through this code
$conn=mysql_connect("localhost","root","") or die(mysql_error());
second database file "config2.php" through this code
$conn2=mysql_connect("localhost","root","") or die(mysql_error());
in my webpage i m calling them as
i m not able to connect to both dbs together.
guido2004 — 2010-04-16T02:25:00-04:00 — #2
Why, what happens? An error?
bagtjesen — 2010-04-16T09:25:08-04:00 — #3
I am not much of a PHP expert but has quite a bit of old programming languages coding experience. So, doesn't including each of them into the same page get the $unique_id only exist once in the session? If so, the $unique_id will be set first to one session_id(), and then to the other. If so, the variable will only contain the session_id() from the last call...?
If that is the case, just do as yuo did with conn and conn2 - have two different names.
If not this is the case, what type of errors do you get and at what kind of line in the code?
guelphdad — 2010-04-16T09:50:55-04:00 — #4
That would be the case Bagtjesen, as soon as the second connection is set to the variable $unique_id it wipes out the information from the first call. Good catch.
vali — 2010-04-16T12:53:39-04:00 — #5
If both databases are on the same host, you can do selects like this:
SELECT database1.table1.field, database2.table2.field FROM database1.table1, database2.table2 WHERE database1.table1.field = database2.table2.field;
It might not be fast, but it works.
On the other hand, your PHP is totally wrong.
1 you can only start the session once.
2 your $unique_id from the first script will be overwritten with the second one.
3 your mysql_select_db from the first script will be overwritten by the second one.
guelphdad — 2010-04-16T14:06:21-04:00 — #6
Another thing to think about. If they are related data why aren't they in the same database?