# How to do multi database

**URL:** <https://discourse.cakephp.org/t/how-to-do-multi-database/2383>\
**Category:** Uncategorized\
**Created:** [April 9, 2017, 6:24am UTC](https://discourse.cakephp.org/t/how-to-do-multi-database/2383 "2017-04-09T06:24:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petreg](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@Petreg](https://discourse.cakephp.org/u/Petreg)\
**Post date:** [April 9, 2017, 6:24am UTC](https://discourse.cakephp.org/t/how-to-do-multi-database/2383/1 "2017-04-09T06:24:38Z")

</div>

Hello everyone, I have a very big doubt and I hope you help me.

I have an application in PHP with no framework. And in this I use a multi-database schema, it works like this:

I have three companies that use the same system, each using its own database, and a base on which all three share. So when logging in, using the shared database, I create the session and inform it of its base, and from there, the user accesses only the data from their respective database.

Well the system has grown, I have an average of 230 clients and I am facing problems with migration, internationalization (the first customer abroad) and so on. So for ease of coding I’m switching the system to CakePHP. But regarding the connection I am having difficulties in making use of the ACL and this one is in the shared base.

Does anyone have a light?

Thanks in advance.

PS: Sorry my English, I’m using Google Translate

---

<div class="post-metadata">

**Author:** ![gerwintmg](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gerwintmg](https://discourse.cakephp.org/u/gerwintmg)\
**Post date:** [April 10, 2017, 7:50am UTC](https://discourse.cakephp.org/t/how-to-do-multi-database/2383/3 "2017-04-10T07:50:00Z")

</div>

In your Model/Table your might want to set something like:

```php
  $this->table($this->connection()->config()['database'].'.users');

```

if you query two different databases at the same time
