I have two databases in same server with same username and pass. Right now I am connecting to only one database, but I would like to connect to both.
For now this is my code, whick connect only to one database:
connect1.php
<?
$servername='localhost';
$dbusername='user';
$dbpassword='pass';
$dbname1='db1';
$dbname2='db2';
$link1 = connecttodb($servername,$dbname1,$dbusername,$dbpassword);
$link2 = connecttodb($servername,$dbname2,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbusername,$dbpassword)
{
$link=mysql_connect ("$servername","$dbusername","$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;
}
?>
I display result in result.php with this code:
<?
require "connect1.php";
$q=mysql_query("select * from table1 where username='test' order by id",link1);
while($nt=mysql_fetch_array($q)){
echo "$nt[location]";
}
?>
I would like to display similar data in result.php, but with connection to db2
How can I do that? Thank you!