If you have your website on one server for testing/development (like this laptop) and your live site on another, it's quite likely that once in a while your database.php file from one or the other will find itself referring to the wrong database. Over at With Cake a solution was proposed to allow you to switch database sources in the app model, however it might be easier to manage by switching at the source of the 'problem'.
With a modification to your database.php file like so:
<?phpclass DATABASE_CONFIG{var $default = NULL;var $live = array('driver' => 'mysql','connect' =>'mysql_pconnect','host' => 'localhost','login' =>'liveusername','password' => 'livepassword','database' =>'livedatabase','prefix' => '','encoding' => 'UTF8');//only takes effect in cake 1.2var $local = array('driver' => 'mysql','connect'=> 'mysql_pconnect','host' => 'localhost','login' =>'localmachinelogin','password' => 'localpassword','database'=> 'localdatabase','prefix' => '','encoding' =>'UTF8');// only takes effect in cake 1.2function DATABASE_CONFIG() { // For Php5 use __constructif (strpos( $_SERVER['SERVER_NAME'], 'dev')!==false) {$this->default = $this->live;} else {$this->default = $this->local;}}}?>
The file itself can be moved while syncing the files for your site, without the risk of suddently bringing your live site offline when it can't find the database. Obviously this tip is redundant if you set up your file updates such that the database file is ignored.
This approach can easily be extended to allow switching of database sources for quick testing and the likes, which I might mention in my next post.











Kind of amusing that everyone decided to post a note on this topic at the same time ;). As I alluded to in the post, if you are not transferring things manually - the above doesn't apply. I'm not an expert in the use of svn and I don't quite follow what your note means though - do you maintain two trees on your development machine, and periodially syncronize them?
There is something I am clearly missing from your explenation ;). How are you copying from your trunk to your live tree? I've used CASE tools in the past, and avoided such issues by preventing the possibility to publish and overwrite certain resources - but if the copy from one tree to the other is a manual step all that using 2 trees achieves is move the problem (of potentially overwriting) to a different place - I assume I am missing somthing rather obvious (such as making the files read-only??), please could you clarify?