title: CakePHP switch database (using same datasource) on the fly?
body: <p>I have tried to build a small function that would be use in controller to switch database on the fly, i must use only one datasource.</p>
  
  <p>On my database.php :</p>
  
  <pre><code>function __construct() {
  
      $server = Configure::read('Server');
  
      if(!empty($server['database'])) $this-&gt;local['database'] = $server['database'];
      $this-&gt;default = $this-&gt;{$server['datasource']};
  
  }
  </code></pre>
  
  <p>Is used to switch database depending on server config. It is working great.</p>
  
  <p>I tried to build up this :</p>
  
  <pre><code>/**
   * Connects to specified database
   *
   * @param array $config Server config to use {datasource:?, database:?}
   * @return array db-&gt;config on success, false on failure
   * @access public
   */
  function dbConnect($config = array()) {
      ClassRegistry::init('ConnectionManager');
      //debug($config['datasource']);
      //$dbInstance =&amp; ConnectionManager::getInstance();
      //$dbInstance-&gt;config-&gt;{$config['datasource']}['database'] = $config['database'];
  
      $db =&amp; ConnectionManager::getDataSource($config['datasource']);
      $db-&gt;disconnect();
      $db-&gt;cacheSources = false;
      $db-&gt;config['database'] = $config['database'];
      $db-&gt;config['persistent'] = false;
      debug($db-&gt;config);
      $db-&gt;connect();
      if(!$db-&gt;isConnected()) {
          $this-&gt;error('!$db-&gt;isConnected()');
          return false;
      }
      return $db-&gt;config;
  }
  </code></pre>
  
  <p>But sadly, everything seems to work but i alwas get data from the same DB using <code>$this-&gt;Player-&gt;find('list')</code> for instance. I tried <code>$this-&gt;Player-&gt;cacheQueries = false;</code> with no more success.</p>