Is there a way to join table from api call (different server)? In my table I store ID of center and centers table is on different server. Now I need a query to join centers table and to select only center name from there. If that is not a possible what is the alternatives?
Asked
Active
Viewed 142 times
0
-
Can you show us some code so we get a better idea how the current situation is? Also a bit more context of your project would be great. There is an excellent entry about [**How to ask a question**](https://stackoverflow.com/help/how-to-ask) on SO. – codedge May 04 '20 at 10:19
-
sorry if my question was not clear. I have a table beneficiaries where I store center_id and that ID came from different server (my apps communicate with laravel passport). Now on index page I need to show center name and I need something like `join(table from different server, 'beneficiaries.center_id', '=', table from different server.id)` – knubbe May 04 '20 at 10:25
2 Answers
1
You can join tables of different databases and even if they are on different servers. You have to use Mysql Federated Engine
You have to create a federated table based on the table at another remote location to use the way you want. The structure of the table have to be exactly same. The idea goes like this:
CREATE TABLE example_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL DEFAULT ''
...
)
ENGINE=FEDERATED
CONNECTION='mysql://remoteuser@remote_host:[port]/federated/example_table';
Then You can simply join using laravel's join function:
...
join('example_table', 'other.center_id', '=', 'example_table.id')
...
Hope this helps you

Malkhazi Dartsmelidze
- 4,783
- 4
- 16
- 40
0
Check join-tables-from-two-different-server for joining from remote server.
Or here to join tables from different databases
If you cannot do the above:
You can use a custom logic within Laravel, to pull the data from the different sources, and then combine it to something useful for you via PHP

Ron
- 5,900
- 2
- 20
- 30