$sql = "SELECT ID FROM DB1.TB1"
$res = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($res)){
$sql1 = "SELECT * FROM DB2.TB1' WHERE ID = '$row[ID]'";
$res1 = mysql_query($sql1) or die (mysql_error());
$row1 = mysql_fetch_array($res1);
}