简体   繁体   中英

Is possible to join two tables (One Mysql, the other Oracle) from two different servers in PHP?

I'll spare the back story, but basically I have two different databases that I retrieve information from. 1 being Oracle (which we've only been given read-only access to) and the other being Mysql (which we have full access to). My problem is there is column in the oracle table that is missing that we would like to pull data from, however that column we need is in the mysql table. Is there a way that I can write a join statement to include this mysql column to the oracle table? I've seen instances online where people have used 'LinkedServers', but I wasn't sure how that worked working in PHP. The DB connections are stored in a php file and the function is called when we want to use that particular database.

tl;dr

Can a user use a join for a mysql and oracle table? if so, how can it be implemented in php when the db info is in a separate php file?

I imagine the sql query would look similar to this:

select
    *
from
    LocalTable,
    [OtherServerName].[OtherDB].[dbo].[OtherTable]

but with some join logic

You cannot join 2 different database vendors. A query is executed by a specific vendor query analyzer.

You can however do the join itself IN php, but would require to dump a lot of info into php. Should be okay for small data sets not okay for large ones...

What you would want to do is copy the data from one vendor into a temp table in the other then execute the join.

For the purpose of this example I will use PDO. I am going to take the oracle data and put it into mysql so that I can use a join on that data...

$oracle_table_b = "select * from mytable";
$oracle_data = $pdo->fetchAll();
$stmt = $pdo_mysql->prepare("insert into mytemptable (mycols)");
foreach ($oracle_data as $row) {
    $stmt->execute($row);
}

//Then run your join

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM