SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict sporkit's Avatar
    Join Date
    Jan 2003
    Location
    DeKalb, IL
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 different database calls?

    im trying to mod my coppermite photo gallery and am having a little trouble. i managed to get the code that lets me put php code in my template.

    the problem is when i try and call another database for my shoutbox i get an error like this....



    and here is the code that im sticking in my template.

    Code:
    // Select the jokes database
        if (! @mysql_select_db("f8klan") ) {
          echo( "<p>Unable to locate the joke " .
                "database at this time.</p>" );
          exit();
        }
      
        // Request the text of all the jokes
        $result = @mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC  LIMIT 0 , 2 ");
        if (!$result) {
          echo("<p>Error performing query: " . mysql_error() . "</p>");
          exit();
        }
      
        // Display the text of each joke in a paragraph
        while ( $row = mysql_fetch_array($result) ) {
          echo("<p><b><em>" . $row["shoutdate"] . "</em></b><br> " . $row["shouttext"] . "<br> <b>" . $row["shoutname"] . "</b></p>");
        }
    	
    
    		 ?>
    i also tried taking out this little bit of code out....

    Code:
    // Select the jokes database
        if (! @mysql_select_db("f8klan") ) {
          echo( "<p>Unable to locate the joke " .
                "database at this time.</p>" );
          exit();
        }
    but am getting this error.

    Code:
    Error performing query: Table 'f8pics.shoutbox' doesn't exist
    i know the problem is that i cant call 2 different databases at one time. does anybody know a way around this?

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, connecting to 2 databases makes your code a bit more complicated. You could always move between databases on your connection or you could open up 2 connections (I don't know how efficiant that is though), then you would pass the link variable (the result from mysql_connect) around and use it when you do mysq_query etc. (then you would do mysql_query('query', $connectionToDatabaseA); etc.)
    - website

  3. #3
    SitePoint Addict sporkit's Avatar
    Join Date
    Jan 2003
    Location
    DeKalb, IL
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by website
    then you would pass the link variable (the result from mysql_connect) around and use it when you do mysq_query etc. (then you would do mysql_query('query', $connectionToDatabaseA); etc.)
    say whhhhhhhhat?

    haha. that seemed a little strange to me. an example would proably help out. is there like a good guide or something out there that i could checkout?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Singapore
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/mysql_connect
    http://www.php.net/mysql_query

    basically you open 2 connetions instead of one but you must pass the link each time you use mysql_query()

    e.g.
    PHP Code:
    $connection mysql_connect($host$user$pass);
    $db mysql_select_db($mydatabase$connection);

    $connection2 mysql_connect($host$user2$pass2);
    $db2 mysql_select_db($mydatabase2$connection2); 

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If both databases are on the same server with the same login information, just select the database instead of opening another connection for it. It's much faster.

  6. #6
    SitePoint Addict sporkit's Avatar
    Join Date
    Jan 2003
    Location
    DeKalb, IL
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by biggulp
    http://www.php.net/mysql_connect
    http://www.php.net/mysql_query

    basically you open 2 connetions instead of one but you must pass the link each time you use mysql_query()

    e.g.
    PHP Code:
    $connection mysql_connect($host$user$pass);
    $db mysql_select_db($mydatabase$connection);

    $connection2 mysql_connect($host$user2$pass2);
    $db2 mysql_select_db($mydatabase2$connection2); 

    thats awsome thanks alot. is calling 2 different databases like this slow?

  7. #7
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It can be, yes.... depends on many factors such as how busy the server is, how good connection you have to the server etc.
    - website


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
  •