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   1066 Views

Avatar
raamklaza

Community Member, 182 Posts

27 June 2009 at 5:40am

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

Community Member, 182 Posts

27 June 2009 at 6:30am

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

Community Member, 215 Posts

27 June 2009 at 6:23pm

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

Community Member, 182 Posts

27 June 2009 at 11:13pm

Prefect just what i was looking for!!!

Avatar
raamklaza

Community Member, 182 Posts

29 June 2009 at 6:03am

Edited: 29/06/2009 6:06am

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

Forum Moderator, 5513 Posts

29 June 2009 at 5:59pm

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