Home

Using @import in your _config.php for Live site Database Details

Have you ever mistakenly overwritten your live site _config.php with your local one? Even if you haven't it can be a pain to keep copying new lines from your local config file to the live one. This little trick means you won't ever have to worry about it again!

First create a file on your live server with the relevant Database info:

mysite/_liveConfig.php

then simply add this line to the bottom of your regular _config.php file:

mysite/_config.php

The @ infront of the include allows it to fail silently when the file does not exist (i.e. on your local server). You can now upload your _config.php file as much as you like without interfering with the live database settings!

About the Author

Name: Pete Bacon Darwin

Comments (2)

  • Another idea: Why not using e.g. Director::isDev()?
    Define the basic database credentials in array form and overwrite some values like username and password in case it is dev/test/live. Though static calls aren't the fastest, you could use defines instead.
    if( Director::isDev() )
    {
    $databaseConfig[ 'database' ] = 'myDevDB';
    }

    Posted by Marc, 02/11/2009 4:27pm (9 months ago)

  • A better method might be to use environment management:

    http://doc.silverstripe.com/doku.php?id=environment-management

    Posted by Hamish, 18/05/2009 4:12am (1 year ago)

RSS feed for comments on this page RSS feed for all comments

Post your comment