SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: 2 different database calls?
-
Jul 3, 2003, 15:42 #1
- 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>"); } ?>
Code:// Select the jokes database if (! @mysql_select_db("f8klan") ) { echo( "<p>Unable to locate the joke " . "database at this time.</p>" ); exit(); }
Code:Error performing query: Table 'f8pics.shoutbox' doesn't exist
-
Jul 3, 2003, 15:55 #2
- 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
-
Jul 3, 2003, 22:21 #3
- Join Date
- Jan 2003
- Location
- DeKalb, IL
- Posts
- 290
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by website
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?
-
Jul 4, 2003, 00:31 #4
- 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);
-
Jul 4, 2003, 05:38 #5
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.
-
Jul 12, 2003, 12:49 #6
- Join Date
- Jan 2003
- Location
- DeKalb, IL
- Posts
- 290
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by biggulp
thats awsome thanks alot. is calling 2 different databases like this slow?
-
Jul 12, 2003, 12:51 #7
- 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