Forgive me because I'm new to PDO. I am not sure if there is a simple solution. I searched the Internet for a while and have not yet found an answer.
I have two different databases that I connect to.
try { $db1= new PDO( "sqlsrv:server=$server;Database = $dbname", $uid, $pwd); $db2= new PDO( "sqlsrv:server=$server;Database = $db2name", $db2uid, $pwd); }
I am trying to combine information from a table in each database based on a common identifier. I need to view information to print a list.
$sql= "SELECT tableA.name, tableB.messages FROM tableA INNER JOIN tableB ON tableA.id = tableB.id"; foreach ($db1->query($sql) as $row) { //HOW CAN I QUERY DB2?? $id = $row['id']; $name = $row['name']; $msg= $row['messages']; echo $name . "etc..."; }
How can I change this code to request both PDOs so that it can print the results in the same foreach loop?
EDIT: I am trying to match the ID in table A with the identifier in table B, and then print the name field in tableA next to the msg field in tableB when the identifiers match.
user1 source share