You can use \Cake\Datasource\ConnectionManager::config(); for setting the 
connection details you need. Check how it is done in the application 
bootstrap.php file.

On Tuesday, September 9, 2014 2:40:08 PM UTC+2, Chris Hickingbottom wrote:
>
> How would I go about changing the database connection on the fly with 
> cakephp 3? 
>
> On Tuesday, September 9, 2014 3:31:47 AM UTC-5, José Lorenzo wrote:
>>
>> You can either have multiple different databses and change the connection 
>> on the fly before you connect to it. That's not bad at all and it is not 
>> inefficient in any way.
>>
>> The other option is to have everything in the same database with an extra 
>> column on each table meaning the owning store. You can make the combination 
>> of the id and the store id a primary key for the table.
>>
>> I would not recommend using table prefixes as that solution is quite 
>> limiting and very complex to implement.
>>
>> On Tuesday, September 9, 2014 12:10:31 AM UTC+2, Chris Hickingbottom 
>> wrote:
>>>
>>> Is there a way to change Database Connections on the fly? Is it 
>>> efficient? We have clients with multiple databases. They each contain the 
>>> same structures, but we keep them separate to use the same classes in our 
>>> application and security purposes. Is there a better way to do this than 
>>> switching database connections? Perhaps have them all in one database and 
>>> use prefixes for each table. Would I be able to change database prefixes on 
>>> the fly?
>>>
>>> To supply more information about my situation. Our client has multiple 
>>> stores that he needs to connect in one application. At the moment, we are 
>>> showing each store in a different application. Because at the time he only 
>>> had one, and now he has three. Each store has its own database. Does that 
>>> help?
>>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to