API page: https://api.drupal.org/api/drupal/includes%21database%21database.inc/fun...

Enter a descriptive title (above) relating to public static function Database::addConnectionInfo, then describe the problem you have found:

For me it wasn't very clear how to use this function in order to add a database at runtime. I was coding a module that needed access to an external database, the documentation led my to believe that I should only use this function once instead of running it again each time the external database is required.

In general I'm finding the database API documentation lacking in info as to when and how functions should be called.


DenEwout’s picture

Title: Not at all clear how/when this should be called. » Not at all clear how/when Database::addConnectionInfo should be called.
jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: -documentation +needs backport to D7

OK. Needs to be fixed in 8.x first, then backported.

dvandusen’s picture

There is more to this.
The problem as I can see from the code is that several modules are involved in the database query that attempt to use the primary default database, and these fail when the default has been changed during the call to, for instance, db_select. To fix that, the call to getConnection from db_select must provide the information needed, without switching out of the connection with the default db.

see https://drupal.org/node/18429#comment-8857521


Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.