Opening multiple databases using mysql_select_db

Discussion in 'PHP' started by joshm, Nov 9, 2007.

  1. #1
    Hi, How can mysql_select_db be used to open 2 databases? I want to open 2 databases and then grab a table from each of them and join them together in a SELECT statement.
     
    joshm, Nov 9, 2007 IP
  2. mybluehair

    mybluehair Peon

    Messages:
    1,374
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hmmm, u could do something like this:

    
    $username="something";
    $pasword="whatever";
    $database="youdatabase";
    $username2="something2";
    $pasword2="whatever2";
    $database2="youdatabase2";
    
    mysql_connect(localhost,$username,$password, localhost, $username2, $password2);
    @mysql_select_db($database, $database2) or die ( "unable to connect");
    
    
    PHP:
    but on second thought that probably wouldnt work. y not just open it 2 times? what exactly are you trying to do?
     
    mybluehair, Nov 10, 2007 IP
  3. joshm

    joshm Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah I think mysql_select_db can only open one DB at a time so it would need to be repeated twice (correct me if i'm wrong). I ended up doing things a different way now. It's too hard to explain because there's a lot of code involved :p Thanks for your help anyway.
     
    joshm, Nov 10, 2007 IP
  4. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You cant actually select 2 different database on 1 connection.

    If you want to access them both youll need to run mysql_connect twice, or else select the new db each time you want to use it.
     
    tonybogs, Nov 10, 2007 IP