title: two database connection: php + mysql
body: <p>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.</p>
  
  <p>For now this is my code, whick connect only to one database:</p>
  
  <p>connect1.php</p>
  
  <pre><code>&lt;?
  $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;
  }
      ?&gt;
  </code></pre>
  
  <p>I display result in result.php with this code:</p>
  
  <pre><code>&lt;?
  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]";
  }
  
  ?&gt;
  </code></pre>
  
  <p>I would like to display similar data in result.php, but with connection to db2</p>
  
  <p>How can I do that? Thank you!</p>