SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Multiple MySQL connections
-
Dec 4, 2000, 04:42 #1
- Join Date
- May 2000
- Posts
- 19
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
I'm throwing together a quick message board and have come across a problem. When a message gets displayed, MySQL gets called upon to grab the message from the database called 'forum'. This happens without toruble, but when I connect to mysql again using a different database to get member infomation, MySQL always gives me an error if I try to work with the data. I don't know if I should be using a single SQL statement to use the two databases or not. The code in question:
Code:// MySQL Login $u = username; $p = password; $d = forum; $db = mysql_connect("localhost", "$u", "$p") or DIE("Unable to connect to database. Please contact system admin."); mysql_select_db("$d",$db) or DIE("Unable to select database. Please contact system admin."); // 2nd MySQL Login $u2 = username; $p2 = password; $d2 = other_database; $db2 = mysql_connect("localhost", "$u2", "$p2") or DIE("Unable to connect to database. Please contact system admin."); mysql_select_db("$d2",$db2) or DIE("Unable to select database. Please contact system admin.");
The script then displays the messages in the thread, and then the member infomation is grabbed:
Code:$members = mysql_query("SELECT * FROM members WHERE username='$author'",$db2); $email = mysql_result($members,0,"email");
Warning: Supplied argument is not a valid MySQL result resource in /web/.../www/forum/showmsg.php on line 68
-
Dec 4, 2000, 04:49 #2
- Join Date
- Jul 1999
- Location
- Derbyshire, UK
- Posts
- 4,411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For the sake of efficeincy you should be using just the one query with the tables joined on username, that way you are saving 1 query to the database.
Karl Austin :: Profile :: KDA Web Services Ltd.
Business Web Hosting :: Managed Dedicated Hosting
Call 0800 542 9764 today and ask how we can help your business grow.
-
Dec 4, 2000, 09:34 #3
- Join Date
- Aug 2000
- Location
- Silicon Valley
- Posts
- 2,241
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Highlight the line 68 so we can see what was wrong, such problems I had before, but it could be other thing (beside multiple connections to MySQL)
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
-
Dec 4, 2000, 17:08 #4
- Join Date
- May 2000
- Posts
- 19
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Line 68 is the last line I mentioned (sorry forgot about that):
Code:$email = mysql_result($members,0,"email");
Thanks,
Andrew.
Bookmarks