Jump to content

Recommended Posts

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.

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.

@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 by jeger003
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.