using 2 or 3 Databases in PHP!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tara83
    New Member
    • Feb 2007
    • 11

    using 2 or 3 Databases in PHP!!!

    i'm having this project where i need to be connected to more than 1 database > i've used php before so any redirection to articles or tutorial would be helpful.

    thnx for your time
  • gubbachchi
    New Member
    • Jan 2008
    • 59

    #2
    Hi,

    You can just use the query in this way,

    mysql_query = "SELECT * FROM database1.table 1,database2.tab le2,database3.t able3 WHERE id='1'";

    With regards

    Comment

    • Tara83
      New Member
      • Feb 2007
      • 11

      #3
      thnx for your reply

      what about the config file? i still need a new statment to connect to 2 DB

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by Tara83
        thnx for your reply

        what about the config file? i still need a new statment to connect to 2 DB
        See the following entry in the mysql_select_db chapter of the PHP manual
        at multiple dbs
        Just incase the mysql_select_db () function still won't work with multiple database connections (as has happened to me before).

        $dbh1 = mysql_pconnect( $host,$user,$pa ss);
        $dbh2 = mysql_pconnect( $host,$user,$pa ss);

        You could do this...

        mysql_query("US E database1",$dbh 1);
        mysql_query("Us e database2",$dbh 2);

        This does the same thing as the mysql_select_db () function...

        or this...

        You don't even have to select the database for each connection.

        mysql_query("SE LECT * FROM database1.table ",$dbh1);
        mysql_query("SE LECT * FROM database2.table ",$dbh2);
        Ronald

        Comment

        • Tara83
          New Member
          • Feb 2007
          • 11

          #5
          appreciate your fast help ronverdonk
          thnx alot

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Originally posted by Tara83
            appreciate your fast help ronverdonk
            thnx alot
            You are welcome. See ya again.

            Ronald

            Comment

            Working...