Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Define your database connections and select your database want to use. In this example I use two connections and two DBs. But you can use more than two.
- //MySQL Server 1
- $dbhost1 = "192.168.34.102";
- $dbuser1 = "dbuser1";
- $dbpassword1 = "dbpass1";
- $db1 = "database1";
- $connection1 = mysql_connect($dbhost1,$dbuser1,$dbpassword1) or die (mysql_error());
- mysql_select_db($db1,$connection1);
- //MySQL Server 2
- $dbhost2 = "192.168.34.3";
- $dbuser2 = "dbuser2";
- $dbpassword2 = "dbpass2";
- $db2 = "database2";
- $connection2 = mysql_connect($dbhost1,$dbuser1,$dbpassword1) or die (mysql_error());
- mysql_select_db($db2,$connection2);
- //The SQL statement
- $sql =" SELECT a.fieldname1 AS field1, "
- ."b.fieldname2 AS field2 "
- ."FROM database1.tablename1 a"
- ."JOIN database2.tablename2 b USING(id)";
- //Execute query and collect results in $results
- $results = mysql_query($sql);
- //Print result until end of records
- while($rows = mysql_fetch_array($results)){
- print $rows["field1"]." | ".$rows["field2"]."<br>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement