Impossible, the only way this is possible in PHP is to use your clusters / multiple nodes with replication settings.
Obviously, you do not understand some of the more technical characteristics regarding mysql, but give it earlier.
$master = mysql_connect("master_host","abc","abcdb"); $slave = mysql_connect("slave_host","xyz","xyzdb"); if(mysql_select_db("abc_db",$master) && mysql_select_db("xyz_db",$slave)) { //Both Selected $sql = mysql_query("SELECT * FROM employee",$master); $rows = array(); while($row = mysql_fetch_assoc($sql)) { //Query the other $slave DB here! $slave_sql = mysql_query("SELECT * FROM department WHERE department_id = " . $row['id'],$slave); while($sub_row = mysql_fetch_assoc($slave_sql)) { $row = array_combine($sub_row,$row); } $rows[] = $row; } }
But that is not what you want to really do.
Just try connecting to two databases on the same server, since your hosts in your code are locahost, this is possible
SELECT * FROM db1.employees db1_e,db2.records db2_r WHERE db1_e.employee_id = db2_r.record_eid
But do not separate 1 to an external server that does not use replication, even then you may not use replication.
Links and links:
http://nathan.rambeck.org/blog/2-joining-mysql-tables-across-multiple-databases
http://dev.mysql.com/doc/refman/5.0/en/replication.html
source share