Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/
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]
Link to comment
https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-25826
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?
Link to comment
https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-26042
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.
Link to comment
https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-26075
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.