Crusader Posted April 10, 2006 Share Posted April 10, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/ Share on other sites More sharing options...
wickning1 Posted April 11, 2006 Share Posted April 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-25826 Share on other sites More sharing options...
fenway Posted April 11, 2006 Share Posted April 11, 2006 It's like no one even bothers to read other active threads..... Quote Link to comment https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-25844 Share on other sites More sharing options...
Crusader Posted April 12, 2006 Author Share Posted April 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-26042 Share on other sites More sharing options...
fenway Posted April 12, 2006 Share Posted April 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7075-dual-mysql-connection/#findComment-26075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.