jeger003 Posted December 4, 2012 Share Posted December 4, 2012 hello, I am using three databases. two of them have the same login information. I want to be able to run different queries on the same page from all three databases. So far i am using this but it only uses the last connection no matter which $handle_db i use. $handle_db1 = mysql_pconnect("othersite.com","user","pass"); mysql_select_db("db1",$handle_db1); $handle_db2 = mysql_pconnect("mysite.com","user1","pass1"); mysql_select_db("db2",$handle_db2); $handle_db3 = mysql_pconnect("mysite.com","user1","pass1"); mysql_select_db("db3",$handle_db3); I tried functions, classes and nothing works. Quote Link to comment https://forums.phpfreaks.com/topic/271593-best-way-to-make-multiple-db-connections/ Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 (edited) Why would you ever need two databases for login information? You can find most of your answers here Edited December 4, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/271593-best-way-to-make-multiple-db-connections/#findComment-1397480 Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2012 Share Posted December 4, 2012 The two that use the same connection information are actually the same connection and would use the last selected database on that connection, unless you specify a TRUE value for the 4th parameter in the mysql_connect statement. Quote Link to comment https://forums.phpfreaks.com/topic/271593-best-way-to-make-multiple-db-connections/#findComment-1397482 Share on other sites More sharing options...
jeger003 Posted December 4, 2012 Author Share Posted December 4, 2012 (edited) @socialcloud - i want to keep connections to dbs separate. if you look at my code it is from that php page but it does not work like the user commented. @PFMaBiSmAd - below seems to be working. Could you possibly explain how this works? I'm trying to understand mysql connections. Also what is the best way to handle errors? I want mysql to tell me all the errors rather than blank pages. $handle_db1 = mysql_pconnect("othersite.com","user","pass"); mysql_select_db("db1",$handle_db1); $handle_db2 = mysql_pconnect("mysite.com","user1","pass1"); mysql_select_db("db2",$handle_db2); $handle_db3 = mysql_pconnect("mysite.com","user1","pass1", TRUE); mysql_select_db("db3",$handle_db3); Edited December 4, 2012 by jeger003 Quote Link to comment https://forums.phpfreaks.com/topic/271593-best-way-to-make-multiple-db-connections/#findComment-1397488 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.