Different enviroment for theme when theme is activate

Hi there,
grate work!! When I start use badrock I just love it! I have a little question how can I configure a DB env. for different theme? I need this because I have different db for theme. Example below:

theme1

DB_NAME = theme1
DB_USER = user_theme1
DB_PASSWORD=''
DB_HOST='localhost'
DB_PREFIX ='theme1__'

theme2

DB_NAME = theme2
DB_USER = user_theme2
DB_PASSWORD=''
DB_HOST='localhost'
DB_PREFIX ='theme2__'

I try to create a new config\environments theme1.php but DB_PREFIX doesn’t work.
I founded this https://github.com/roots/bedrock#deployment-steps but this is on ruby there is the way to do this without using ruby?
Regards

Pretty sure this wouldn’t be supported in Bedrock or WordPress in general. Your database credentials are set up in wp-config.php, this is long before the Theme is chosen. In fact, since WP records the current theme WITHIN the database, what you’re requesting doesn’t make much sense.

Unless I’m misunderstanding your question.

Maybe I was not clear. Sorry for that. My solution make sense when you have one installation of WP with a few themes. And each of theme has different data stored in DB (posts, short codes, Theme Options etc.) It will be enough to set up:

WP_ENV=theme1

but in application.php is:

$table_prefix = getenv('DB_PREFIX') ? getenv('DB_PREFIX') : 'wp_';

and I can’t configuration DB PREFIX from env. file.

Are you sure? 20 chars

Yes I’m sure. When I put this code:
define(‘DB_PREFIX’, ‘theme1__’);
in
…\config\environments\theme-development.php
and not set up in .env file DB_PREFIX always is wp_
Regards

So I think we’r talking about the same thing… define() sets up constants. The .env file sets up environment variables. They’re not the same thing. To get environment variables you use getenv().

However, I just tested on a relatively new version of Bedrock. In .env I added DB_PREFIX=hello_ and refreshed my site, and I get redirected to install WP. So on a default installation this should be working.

Yes I know that. From .env file everything works correct but I try to move all DB configuration to php file and in .env file just change one line
WP_ENV=theme1 or WP_ENV=theme1-development
But defined DB_PREFIX in php file do nothing because this line is in application.php:
$table_prefix = getenv(‘DB_PREFIX’) ? getenv(‘DB_PREFIX’) : ‘wp_’;

Or maybe you have different suggestion to do this?
There is the way to set env. variable form php?
Regards

No, I don’t have another suggestion for you. If $table_prefix = getenv('DB_PREFIX') ? getenv('DB_PREFIX') : 'wp_'; doesn’t work for you, then change it. I wouldn’t suggest loading different databases based on theme, but why couldn’t you just do this in PHP?

if (getenv('WP_ENV') == 'theme1') {
  define('DB_PREFIX', 'theme1_');
} elseif (getenv('WP_ENV') == 'theme2') {
  define('DB_PREFIX', 'theme2_');
}

OK thanks. I don’t like to change files depending on library because when I update it my changes disappear.

I added this code below:

if (defined('DB_PREFIX')) {
	$table_prefix = DB_PREFIX;
} else {
	$table_prefix = getenv('DB_PREFIX') ? getenv('DB_PREFIX') : 'wp__';
}

I found better solution to do this:

Dotenv::setEnvironmentVariable('DB_PREFIX', 'theme1__');