Cakephp can't change database on-the-fly

前端 未结 2 1502
一向
一向 2021-01-21 01:52

I am trying to connect from multiples databases from a loop, but seens CakePHP can\'t change database, only others infos (like user/pass/host).

app/

相关标签:
2条回答
  • 2021-01-21 02:05

    Try not to drop config, just alter the things you need.

    For this task I successfully use

    $dataSource = ConnectionManager::getDataSource('company_data');
    $dataSource->config['schema'] = 'company_'.$id;
    

    I don't know if database switching and mysql as engine is good pair. I use postgresql schemas for this purpose.

    0 讨论(0)
  • 2021-01-21 02:21

    You can use the model method setSource() to change the table or setDataSource() to change the db config.

    0 讨论(0)
提交回复
热议问题