Jump to content

Connect two databases at the same time, different servers


flywheeler

How can you have 2 active connections to 2 databases?  

  1. 1. How can you have 2 active connections to 2 databases?

    • 1
      0
    • 2
      0


Recommended Posts

I got a super tricky problem!!!

 

In PHP, how can you have 2 active connections to 2 databases that are on 2 different servers at the same time inside a while loop?????

 

I've tried this already:

 

$db1 = mysql_pconnect($hostname1, $username1, $password1) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_1, $db1);

 

 

$db2 = mysql_pconnect($hostname2, $username2, $password2) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_2, $db2);

 

...and then I do my thing inside a while loop, and it only connects to one database.

 

Any ideas????

 

thanks,

Ali

 

 

Link to comment
Share on other sites

There is an issue with mysql_pconnect in which if you are connecting to multiple databases you need to specify the socket path. In other words, if the database is on your localhost, you would specify mysql_pconnect('localhost:3306'... assuming of course the port hasn't changed from the default 3306. Hope this works for you!!!

Link to comment
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.