Switching from development to production

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cols2910
Forum Newbie
Posts: 5
Joined: Thu Sep 10, 2009 2:36 pm

Switching from development to production

Post by cols2910 »

Hi everyone

I have a config.ini file that contains the following

[development]

debug = true
database.host = localhost
database.database = dbname
database.username = username
database.password = password


[production]

debug = false
database.host = localhost
database.database = dbLive
database.username = root
database.password = pass

I have used parse_ini to parse the file and I can then retrieve the values of the various settings. However, is there an easy way to tell my application to use the settings in [development] or [production]? I'm sure I did this before but for the life of me I can't figure out what I did.

Many thanks,
Cols2910
cols2910
Forum Newbie
Posts: 5
Joined: Thu Sep 10, 2009 2:36 pm

Re: Switching from development to production

Post by cols2910 »

Aha. Thats what I have been missing.

Many thanks McInfo

Regards,
Cols2910
cols2910
Forum Newbie
Posts: 5
Joined: Thu Sep 10, 2009 2:36 pm

Re: Switching from development to production

Post by cols2910 »

Hi McInfo (or anyone else who wishes to jump in here)

I have been wracking my brains trying to access the desired variables which I can by doing

$config = parse_ini_file("config/config.ini", true);

if($config['development.debug'])
{
// do sometihing
}

However, I'm still unsure as to how to tell my application to i=use either the development settings or the production settings. I have tried numerous combinations such as

$config[development][debug]

but to no avail. Using 'development.debug' works but how would I tell the application to use the [development]->settings or the [production]->settings?

Many thanks,
Cols2910
cols2910
Forum Newbie
Posts: 5
Joined: Thu Sep 10, 2009 2:36 pm

Re: Switching from development to production

Post by cols2910 »

Okay I think I finally figured it out

$environment = 'development'; //switch this between production / development
$config = parse_ini_file("config/config.ini", true);

$settings = $config[$environment]['database.username'];

I'm sure there is maybe a better way to do this so if anyone has any suggestions, please feel free to post them here.

Thanks,
Cols2910
cols2910
Forum Newbie
Posts: 5
Joined: Thu Sep 10, 2009 2:36 pm

Re: Switching from development to production

Post by cols2910 »

Good idea McInfo. I'll run with that suggestion.

Many thanks,
Cols2910
Post Reply