SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Another database, or another table?

  4. #4
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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.

  7. #7
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @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

  8. #8
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's ok

    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.

  9. #9
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •