Jump to content


Photo

dual mysql connection


  • Please log in to reply
4 replies to this topic

#1 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 10 April 2006 - 11:44 PM

Right now I've got it connecting to the DB in an include and everything right now just uses that connection.

I also have it connect to another DB on the same server to get a recent list of posts. Now I included the mysql_connect/pconnect in the function itself but if I place it at the top of the page the SQL data for the initial connection doesn't work and it looks to the second connection for the data.

How would I keep them sepearate? I'm trying to keep everything O.O. so I'd like to keep it at 2 connections max.

Note: I have multiple functions.

Thanks

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 11 April 2006 - 12:32 PM

If it's a database on the same server you can use the first connection, just specify database name in your query. For instance:

SELECT * FROM theotherdatabase.table
You can also maintain two connections by keeping track of the resource returned by mysql_connect().

For instance:

$conn1 = mysql_connect(...FIRST DATABASE...);
$conn2 = mysql_connect(...SECOND DATABASE...);
$result = mysql_query(...QUERY FIRST DATABASE..., $conn1);
$result2 = mysql_query(...QUERY SECOND DATABASE..., $conn2);


#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 April 2006 - 01:47 PM

It's like no one even bothers to read other active threads.....
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 12 April 2006 - 12:08 AM

Sorry if this was already covered, it's been 3 or 4 years since I've actively read this place.

And thanks for the tip but they're on the same server but they're two different databases.

One is an Invision Forum database, we'll call it db1_ibrd1, and the other is in another database called news. Does your example only work with column names or for different databases altogether?

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 12 April 2006 - 03:37 AM

I just mentioned that because another user posted the exact same question the other day.

If they're on the same server AND have the same login credentials, then you can use the fully-qualified DB.TABLE.COLUMN syntax; otherwise, you have to use two different connections, AFAIK.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users