# Fetch data across multiple databases

**URL:** <https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796>\
**Category:** Uncategorized\
**Created:** [October 11, 2021, 1:07pm UTC](https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796 "2021-10-11T13:07:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![armin](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@armin](https://discourse.cakephp.org/u/armin)\
**Post date:** [October 11, 2021, 1:07pm UTC](https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796/1 "2021-10-11T13:07:25Z")

</div>

hi,  
we’ve been using that feature in cakephp 2.x for years now.  
after upgrading to cakephp 4.2 this seems to be no longer available, am i right?

regards, armin

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [October 11, 2021, 1:39pm UTC](https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796/2 "2021-10-11T13:39:08Z")

</div>

You can use the `setConnection` method of the table to indicate which connection should be used for that table.

---

<div class="post-metadata">

**Author:** ![armin](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@armin](https://discourse.cakephp.org/u/armin)\
**Post date:** [October 11, 2021, 11:33pm UTC](https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796/3 "2021-10-11T23:33:47Z")

</div>

thanks for your quick response. i tried that but i was unable to link data. it seems that cakephp tries to join on a database level, which is of course not possible when hosted on different databases.

just fetching data one after the other works, but it seems you have to join data manually in php’s memory. in cake 2.x it was possible to retrieve data by cake (w/o merging manually). cake joined all data and provided a fully prepared array that could be used in both controller and view.

it seems that this feature is gone, am i right?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [October 12, 2021, 5:31pm UTC](https://discourse.cakephp.org/t/fetch-data-across-multiple-databases/9796/4 "2021-10-12T17:31:15Z")

</div>

I’ve never needed it, but I thought it was possible. You might have to change the strategy on the association definition from `join` to `select`?
