function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
$link=mysql_connect ("$servername","$dbuser","$dbpassword",TRUE);
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
return $link;
}
$link1 = connecttodb($servername1,$dbname1,$dbusername1,$dbpassword1);
$link2 = connecttodb($servername2,$dbname2,$dbusername2,$dbpassword2);