I am trying to get data from two different databases in a controller
app/Controller/UsersController.php
my db connections are declared in the database.php
$default = array(
...
'database' => 'test'
...
);
$test = array(
...
'database' => 'test1'
...
);
and in my display() action:
public function display() {
$this->set('defaultUsers', $this->User->find('all'));
$this->User->schemaName = 'test1';
$this->User->cacheQueries = false;
$this->set('testUsers', $this->User->find('all'));
}
This would allow me to grab data from two different sources successfully, however problem is that these two databases have to have the same password otherwise it wouldn't work.
I've tried other solutions found here and other sites. like:
changing
$this->User->useDbConfig = 'test'and$this->User->cacheQueries = falsewould still give me the same dataset;using
ConnectionManager::getDataSource()andsetConfig(),create(),drop(),setDataSource(), etc. None of those worked and some don't even exist any more.
Any help would be greatly appreciated! As I need to the same codebase for two similar applications a.k.a two databases.
Thanks!