SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can i connect two databases at a time?

    Hi all,
    I have two databases in my server.
    I want to access the two databases data in a page..

    For header portion of the page, i used database1.
    For body portion of the page, i used database2.

    But in the body, i didn't get the data..

    Is there any wrong to do so..

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can create two PDO objects, for example. What code are you using now?

  3. #3
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    //passing variables from some other page.

    mysql_connect($server,$username,$password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());

    but when i include header portion, the body of the page accessing from the second database is not getting..
    where as without header( removing header part code), it is working...
    why?

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't tell if you mean <head>, <header>, header(), navigational header or some sort of include. Could you paste in all of the code (removing the database details)?

  5. #5
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see this page...
    Design New Cable

    Am including the 5-6 pages, in this page..
    When you mouse over on the menu items, it is showing data...

    but select box is not populated...
    why?

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP/MySQL will use the last available connection for the queries.
    So, before the head you add your connection code:

    PHP Code:
    mysql_connect($server,$username,$password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error()); 
    and just before you include the body part of your page, connect again

    HTH
    Yours truely
    Mário Ramos

  7. #7
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you mjpr...
    After changing the code as you specified, now it is working.
    I solved the problem...

    Thanks again..


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
  •