Cakephp can't change database on-the-fly

前端 未结 2 1503
一向
一向 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.

提交回复
热议问题