title: How do I construct a cross database query in PHP?
body: <p>In our last episode (<a href="https://stackoverflow.com/questions/1972943/how-do-i-construct-a-cross-database-query-in-mysql">How I constructed a cross database query in MySQL</a>) I learned how to construct a cross database query in MySQL. This worked great but when our hero tried to use this newfound knowledge in PHP he found his best friend FAIL waiting for him.</p>
  
  <p>I took a look at <code>mysql_select_db</code> for PHP. This seems to imply that if I want to use MySQL with PHP, I have a couple of choices:</p>
  
  <ol>
  <li><p>Use <code>mysql_select_db</code> but be stuck with only using one db at a time. This is our current setup and putting a database as a namespace identifier doesn't seem to work (it works fine in the MySQL shell so I know it's not a problem with our MySQL server setup).</p></li>
  <li><p>Don't use <code>mysql_select_db</code>. From some of the examples I've seen, this seems to mean that I have to specify the db for every query that I make. This makes sense since I haven't used <code>mysql_select_db</code> to tell PHP what db I want to access. This also makes sad since I don't want to go through all my code and prepend a db name to every query.</p></li>
  </ol>
  
  <p>Is there something better than this? Is there a way for me to do a cross db MySQL query in PHP without having to something crazy like (2)?</p>
  
  <p><strong>CLARIFICATION</strong>: None of the proposed answers actually let me do a cross db query. Instead, they allow me to access two different DBs separately. I want a solution that allows me to do something like <code>SELECT foreign_db.login.username, firstname, lastname from foreign_db.login, user where ...</code> NOT just make different queries to different DBs. For what it's worth, (2) doesn't work for me.</p>