Results 1 to 7 of 7
  1. #1
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    2 databases on one page
    I am trying to use two different databases on the same page (not tables databases) is this possible and could anyone tell me how to do it please?

    I use this on my pages "require_once("./1config.php");" for the main scripts and this is the info on the 1config.inc.php
    $db_user = "xxxx"; // Database user name
    $db_pass = "xxxx"; // Database password
    $db_name = "xxxx_xxxx"; // Database name
    $db_host = "localhost";
    I have tried to add the other bit of script using a different database again by using the "require_once("./2config.php");" call and the info on this file is exactly the same as the above except for the 2nd part of the database name.

    Now my problem is when I add this to the pages just after the <body> tag somehow the database name is carried onto the script that is suposed to use the 1config.php info. Is there any way to do this please?

    thanks in advance
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  2. #2
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    Hi Gordon,

    Not sure if this will work but if you are only using /2config.php that one time and not anymore, have you tried closing the database using mysql_close()after you're done with using that database and then kick off using /1config.php later on the script? And also make sure you haven't used the mysql_pconnect but the mysql_connect function when calling your database.

    I'm no expert so I could be wrong...

    Oscar

  3. #3
    Not Verif-Lidated infoTim's Avatar
    Join Date
    January 18th, 2005
    Location
    Sunny Florida
    Posts
    1,021
    It's possible to use more than one. Your second file needs to be something like

    $db_user2 = "xxxx";
    $db_pass2 = "xxxx";
    etc...

    and you'll need another mysql_pconnect() to use that second database's information with a different set of variables.
    Tim
    consultant by day, affiliate by night

  4. #4
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I'd use a single database class and simply issue a "use other_database" mySQL command. If your code uses the $db_name variable upon every query, you'll need to change that variable to the new DB name. Really just depends on how the code is structured. When you get down to it, you simply need to execute the "use database" mySQL command which will change the current DB.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  5. #5
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    thanks guys I'll play with these sugestions and let you know how I get on.
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  6. #6
    Member
    Join Date
    January 18th, 2005
    Posts
    64
    Let me know if this worked, this has shooted a serious of creative ideas in my mind

  7. #7
    ABW Ambassador FFoc's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,015
    Exclamation
    Quote Originally Posted by Gordon
    I am trying to use two different databases on the same page (not tables databases) is this possible and could anyone tell me how to do it please?
    you could use $db_*_1 and $db_*_2, then do everything twice..

    OR, you could do:
    PHP Code:
    do {
      if (!
    exists("$count"'config.inc.php')) break; // breaks the while loop if the config don't exist  :)
      
    include("$count'config.inc.php');
      
    $db[] = mysql_connect ($...); // or use pconnect..
      
    count++;
    } while (
    1); 
    then use $db[0], $db[1], etc later in the code..

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Where, oh where did my databases go......
    By bettylou in forum Midnight Cafe'
    Replies: 16
    Last Post: October 7th, 2008, 08:32 PM
  2. 50% off in all databases
    By pachecus in forum Midnight Cafe'
    Replies: 1
    Last Post: June 12th, 2006, 10:54 AM
  3. Using ASP, but need help with databases
    By bcorso in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: August 19th, 2003, 03:30 AM
  4. MS Access Databases
    By Taurus in forum Programming / Datafeeds / Tools
    Replies: 24
    Last Post: January 22nd, 2002, 01:58 PM

Posting Permissions

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