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