It looks like you're new here. If you want to get involved, click one of these buttons!
Hello,
QUESTION:
How can I configure to use one database connection for the environment "development"
and
ANOTHER database connection for the environment "production".
=====================================
config/database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'server-livesystem.de',
'username' => 'username-livesystem',
'password' => 'pw-livesystem',
'database' => 'db-livesystem',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['dev'] = array(
'dsn' => '',
'hostname' => '127.0.0.1',
'username' => 'username-development',
'password' => '',
'database' => 'db-development',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'development'),
....
======================================
config/environments.php
(https://docs.getfuelcms.com/general/environments)
$environments = array(
'development' => array(??????),
'production' => array(???????),
);
Comments
This may help:
https://stackoverflow.com/questions/8268853/codeigniter-multiple-database-connections
For FUEL, the default database connection should be relegated to the fuel tables. For models using a different database connection, there is a
dsn
protected property you can specify on the model to point to the other database:https://docs.getfuelcms.com/libraries/my_model
Hello admin ... thanks for your quick reply ...
... I KNOW howto to use different databases ... as described in the links you provided.
...sorry ( I was not clear enough in my initial posting )
BUT ...
I THOUGHT there is a way to define different ENVIRONMENTS:
a) development-env
b) production-env.
because .. my development stuff is on localhost...with different dbuser and dbpassword
BUT ... my production system is on a remote server ...
It would be nice to define 2 environments (development and production) with different database configs ( localhost and productionserver) ...and use a switch (e.g. a parameter in one of the config files ) to define, which environment should be used....
/fuel/application/config/environments.php
the userguide tells not much about the usage/meaning of:
$environments = array(
'development' => array('localhost', '192.', '*.dev'),
);
/fuel/application/config/database.php
I defined different database groups to use different databases in my modules
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'dev-user_1',
'password' => 'dev-paswd_1',
'database' => 'dev-db_1',
...);
$db['second'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'dev-user_2',
'password' => 'dev-paswd_2',
'database' => 'dev-db_2',
....
The production-system has different hostnames, username and password.
QUESTION
Is there a way to define environment-dependend database settings?
At the moment my procedure is, that the development settings ( see above ) are checked-In my source-control (SVN) ... and I manually changed these settings on the production system.
QUESTION
I assume it is bad practice to check-in production-hostnames, -username and -password in my source-control (SVN).
FUEL does not have a .env file that it uses (either does CodeIgniter 3... 4 does). You could setup conditional code in your
database.php
file to look for adatabase-local.php
file and include it:Thanks!