Can I have a separate database config file?

… Something like CodeIgniter config/database.php file.


In main config:

        'db' => require(dirname(__FILE__) . '/db.php'),


return array(

            'connectionString' => 'mysql:host={host_in};dbname={dbname_in}',

            'emulatePrepare' => true,

            'username' => '{username_in}',

            'tablePrefix' => '{tablePrefix_in}',

            'password' => '{password_in}',

            'charset' => '{charset_in}',

            //'nullConversion' => PDO::NULL_EMPTY_STRING,


    	//'enableParamLogging' => true,


The db.php has to contain a valid config of course…

I usually don’t add that particular file to source control (for obvious reasons :P )

Great, thanks.

Of course you can do this, but having tried it I have to say that I didn’t quite like it. It was troublesome to manage when different component configuration were in different files.

What I do love is the approach taken on the Yii site: having a main.php (version controlled) and main-local.php and then merging both in the application entry script (index.php). This is amazing because then you can simply configure Gii on your localhost by adding it to main-local.php without having to worry about Gii getting enabled in the production environment.

I am using different configurations and it really doesn’t bother me at all. :)

One db.php on my server, one on my development machine.

You seem to think there’s a conflict between that and the merge array trick.

I am using both.

However, if you really need different db configs on the same machine, then… :


return CMap::mergeArray(

    require(dirname(__FILE__) . '/main.php'),


        // application components

        'components' => array(

	'db' => require(dirname(__FILE__) . '/db_local.php'),


@jacmoe: It’s not that but I just like having everything in the same file. Besides with the main and local I haven’t had the need to split up my configs into multiple files. My local config is never that long and having everything in the main config file makes it easier to manage everything.

I do that because I don’t want that information in my repository - don’t want to put passwords under source control. :)

I’ve separated out my url rules as well, but that’s because it’s making the main config too big.