Multiple Database Connections - showing ID from one.
Posted: Wed May 20, 2015 5:01 am
We have a few web sites where we connect to multiple databases as they use the same stock codes.
In this scenario, ( a slimmed down version ) we are trying to check if the same price reductions are across multiple sites.
Problem is, it's only echoing the ID from the first $db1 connection. I just cannot see why.
Have I made some stupid error here?
In this scenario, ( a slimmed down version ) we are trying to check if the same price reductions are across multiple sites.
Problem is, it's only echoing the ID from the first $db1 connection. I just cannot see why.
Have I made some stupid error here?
Code: Select all
$db1= mysql_connect("localhost","root","");
mysql_select_db('db1test', $db1);
$db2= mysql_connect("localhost","root","");
mysql_select_db('db2test', $db2);
$db3= mysql_connect("localhost","root","");
mysql_select_db('db3test', $db3);
$result = mysql_query ("SELECT * FROM products WHERE romancode = 'AG045'", $db1);
while ($row = mysql_fetch_object($result))
{
$resultjag = mysql_query ("SELECT id AS jagid, datepricedrop, pricedrop, price FROM products WHERE romancode = '$row->romancode'", $db2);
while ($rowjag = mysql_fetch_object($resultjag))
{
$resultjbbg = mysql_query ("SELECT id, datepricedrop, pricedrop, price FROM products WHERE romancode = '$row->romancode'", $db3);
while ($rowjbbg = mysql_fetch_object($resultjbbg))
{
echo "$rowjag->jagid - $row->id";
}}}