0

I have two connection string user DBO:

string1:

try {
$conn1 = new PDO('mysql:host=ip1;dbname=db1','root', '123456');
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} 
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} 

string2:

try {
$conn2 = new PDO('mysql:host=ip2;dbname=db2','root', '123456');
$conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} 
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} 

i using join query for join tb1 to tb2:

$stmt = $conn1->prepare(" select db1.*,db2.col1 from db1 left join db2 on db1.col1=db2.col2");
$stmt -> execute();
$result=$stmt->fetchAll();
if(count($result)){
foreach($result as $row){
echo $row[col1]";
}}
else{
Echo 'Not rows';                                          
}
}
catch(PDOException $e){
echo $e->getMessage();
}

It not work. i have tried $stmt = $conn1,$conn2-> prepare... and it not work too. i wrong something?

mrdragon
  • 247
  • 1
  • 2
  • 14
  • Are you trying to connect 2 different databases where you want to make a join over 2 DBMS servers ?!?! If yes this won't work! If you want "JOIN data" over 2 different servers you need to grab the data individual from both server and then join them up together in your php – Rizier123 Apr 10 '15 at 06:22
  • 1
    This might be of some help. http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers – Ankit Kumar Apr 10 '15 at 06:30

1 Answers1

0

You did't mentioned Tables name in your join statement. I think you may want to do something like this :

SELECT * FROM db1.table_name as d1 LEFT JOIN db2.table_name as d2
ON d1.col1 = d2.col2

Try to replace your real Tables name with table_name in db1 and db2 in above statement.

Hamed Kamrava
  • 12,359
  • 34
  • 87
  • 125