title: Working with multiple databases in php/mysql
body: <p>I am working on a project needing me to work with multiple database connections. From what I have read, I should be able to switch between connections in the query itself, something like:</p>
  
  <pre><code>mysql_query("SELECT * FROM user_types", $db_core)or die(mysql_error());
  </code></pre>
  
  <p>But I receive the error:</p>
  
  <pre><code>Table 'db_company.user_types' doesn't exist
  </code></pre>
  
  <p>So I can see it is looking at the incorrect db, it is grabbing the last <code>mysql_select_db</code></p>
  
  <p>I wouldn't want to have to re-select the database everytime but if that is the better way to go I can.</p>
  
  <p>I have the databases selected like so:</p>
  
  <pre><code>&lt;?
  $currentpage = $_SERVER["REQUEST_URI"];
  //Core DB
  $db_core_host = "localhost";
  $db_core_username = "root";
  $db_core_password = "";
  $db_core_name = "db_main";
  //
  $db_core = mysql_connect($db_core_host,$db_core_username,$db_core_password);
  mysql_select_db($db_core_name, $db_core)or die(mysql_error());
  //Company DB
  $db_company_host = $company['db_server'];
  $db_company_username = $company['db_username'];
  $db_company_password = $company['db_password'];
  $db_company_name = $company['db_name'];
  //
  $db_company = mysql_connect($db_company_host,$db_company_username,$db_company_password);
  mysql_select_db($db_company_name, $db_company)or die(mysql_error());
  ?&gt;
  </code></pre>
  
  <p>Not sure if it helps at all but when I echo either of the database connections I get Resource id #5</p>