Jump to content

Simultaneous connection to 2 different databases on 2 different servers


flywheeler

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

 

 

Here is my code (I really appreciate you looking at this):

 

 

 

//login to database1

$hostname_dw_db = "192.168.210.50";

$database_dw_db = "db1";

$username_dw_db = "flywheel";

$password_dw_db = "mypass1";

$dw_db = mysql_pconnect($hostname_dw_db, $username_dw_db, $password_dw_db) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_dw_db, $dw_db);

 

//login to database2

$hostname_heart_db = "82.100.100.1";

$database_heart_db = "db2";

$username_heart_db = "flywheel";

$password_heart_db = "mypass2";

$heart_db = mysql_pconnect($hostname_heart_db, $username_heart_db, $password_heart_db) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_heart_db, $heart_db);

 

$sql = "select * from lead_stats order by id asc limit 5;";

$result = mysql_query($sql,$dw_db);

 

while ($row = mysql_fetch_assoc($result)) {

 

$lead_id = $row["lead_id"];

 

$sql_1 = "select * from buysell order by buysell_id asc limit 5;";

$result_1 = mysql_query($sql_1,$heart_db);

 

while ($row_1 = mysql_fetch_assoc($result_1)) {

 

$bstype = $row_1["bstype"];

 

echo "From Heart: ". $bstype;

 

}

 

echo "From DW: ". $lead_id;

 

}

 

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.