How can I show a logged in user his data, when the data is in a second db?

A site that has a db that holds the login info for users username pwd and profile info. I want to add another db holding user data that I want shown when the user visits their pages.

How do I associate the logged in user with his data in the second db.

The second db is not created yet so I have freedom to create it as I want, but it must be separate from the db with the login info.

I know that this is probably one of those things that php and mysql developers do all the time, but I have drawn a blank on understanding how to do this. Therefore any help would be appreciated
Thanks

once the user has been logged in, you should be able to just connect to the second database in the same way you connected to the 1st database, to check their username/password, but this time using the paramaters of the 2nd database.

Another database, or another table?

Thanks for the replies, really appreciate it.

@Guido2004 another database that will have many tables.

@Kalon

once the user has been logged in, you should be able to just connect to the second database in the same way you connected to the 1st database, to check their username/password, but this time using the paramaters of the 2nd database.

OK so would I need to use a field from the user db to associate the data in the second db. Therefore I would have to create a field in the second db that appears in the first db to make the link.

Here is my attempt in psuedo code

$mysql_result=mysql_query("SELECT * FROM dbname and tablename1, tablename2,tablenameN WHERE id="value-from-first-db,showfields;

I do not know whether that helps, I am trying to learn this stuff and my head hurts.

Thx

The only way I know how to do it is to have a table in the 2nd db that contains just the usernames from the users table in the 1st db.

Every time you add a user to the users table in the 1st database your code will have to add just the new username to the users table in the 2nd db.

but out of curiosity, why can’t you use just the one database?

You could use a numeric ID (i.e. the user id) to associate the first table’s data with the data in the other database’s user table.

@Kalon: The reason I need to use another db is that the login info is in a db created by a proprietary piece of software, and if an update is done to that software, I would have no control over what it might do to any other tables I create.

@Immerse: Thats sounds the way to go.

Thanks everyone for your help

that’s ok :slight_smile:

but unless I’m missing something, whether you use the userID or a username (assuming they are both unique) it makes no difference which you use.

True, unless the user wants to change their username. Then you’d need to update it in two separate databases instead of just one. Nobody ever wants to change their user id (usually you don’t even know you have one).

If the username is immutable, then it doesn’t make a difference.