Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

How to: _config uses right db connection locally and on prd


Reply

6 Posts   998 Views

Avatar
raamklaza

27 June 2009 at 5:40am Community Member, 182 Posts

Hello,

how can i make my _config always choose the right db connection?

To often i copy something from local to production without changing the db settings and then my site it down.

How can i solve this easily in the _config?

// Local
global $databaseConfig;
$databaseConfig = array(
   "type" => "MySQLDatabase",
   "server" => "localhost",
   "username" => "xxx",
   "password" => "xxx",
   "database" => "xxx",
);

// Production
global $databaseConfig;
$databaseConfig = array(
   "type" => "MySQLDatabase",
   "server" => "localhost",
   "username" => "xxx",
   "password" => "xxx",
   "database" => "xxx",
);

Avatar
raamklaza

27 June 2009 at 6:30am Community Member, 182 Posts

if server is localhost, 127.0.0.1 {
use local db settings

else id server is domainname, ip {
use production db settings

How do i convert that so a language Silverstripe understands? :)

Avatar
Howard

27 June 2009 at 6:23pm Community Member, 215 Posts

Hey yea there are a few ways to do this, have a look at this [url]http://ssbits.com/using-import-in-your-config-php-for-live-site-database-details/[/url]

Avatar
raamklaza

27 June 2009 at 11:13pm Community Member, 182 Posts

Prefect just what i was looking for!!!

Avatar
raamklaza

29 June 2009 at 6:03am (Last edited: 29 June 2009 6:06am), Community Member, 182 Posts

I take back my precious reply...

I doesn't work "anymore"

I get the following message...

[Warning] mysql_connect() [function.mysql-connect]: Access denied for user 'Liveusername'@'localhost' (using password: YES)
GET /4-Productie/xxx.nl/

Line 35 in C:\wampserver\www\4-Productie\xxx.nl\sapphire\core\model\MySQLDatabase.php

_config.php

<?php

....
@include '_liveConfig.php';

?>

_liveConfig.php

<?php

// Production
global $databaseConfig;
$databaseConfig = array(
   "type" => "MySQLDatabase",
   "server" => "localhost",
   "username" => "livename",
   "password" => "livepassword",
   "database" => "livedbname",
);

Director::isLive('http://www.xxx.nl');
if(Director::isLive()) Debug::send_errors_to("richard.duinmayer@gmail.com");

?>

Does anyone know another way to solve this?

Avatar
Willr

29 June 2009 at 5:59pm Forum Moderator, 5511 Posts

Maybe try an environment file to store your settings - http://doc.silverstripe.com/doku.php?id=environment-management