0

The use case is the following:

I am in default site. I want to get the connection of the "preview" site instance database from the default site code. How is it possible?

I tried Database::setActiveConnection('preview')), but it didn't help. setActiveConnection method seems to choose only from your site settings.php.

* WORKAROUND *

If you want to handle multiple database under one site instance then you should declare their connection array under your site's settings.php!

1 Answer 1

1

You can't.

Multi-site is only about sharing the code in the file system. Unless you actually add the database connections to the specific settings.php, Drupal doesn't even know that there are other sites.

Functionally, once the bootstrap and site selection happened, there is 0 difference between two different installations and a multi-site.

IMHO, there are more downsides than advantages with multi-sites these days, you can use git and e.g. different branches to share code between multiple sites at least as well, with way more flexibility and options for updating and customizing them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.