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.
Why, what happens? An error?
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?
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.
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.
Another thing to think about. If they are related data why aren't they in the same database?