Jump to content

Archived

This topic is now archived and is closed to further replies.

Crusader

dual mysql connection

Recommended Posts

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

Share this post


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

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

For instance:

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

Share this post


Link to post
Share on other sites
It's like no one even bothers to read other active threads.....

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.