Recess Developer Forums: Maintaining two database connections through recess - Recess Developer Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Maintaining two database connections through recess Rate Topic: -----

#1 User is offline   jasonlally Icon

  • Group: Members
  • Posts: 2
  • Joined: 30-September 09

Posted 30 September 2009 - 02:13 PM

I would like to have the ability to run a local copy of my site when I need to do development and testing offline. I have a local development environment set up and was wondering if there was an easy way to maintain two connection scripts, one for a remote environment and one for a local environment.

There are two solutions I'm thinking of that would probably work, but I was wondering if there were any others.

First, I think I can just maintain the same username/password and database on my local computer and the remote host (luckily I can connect to localhost on both), however this is not always the situation.

Second, I guess I could keep separate configuration files and not sync them ever when I push updates to the remote host, so that the local config would have one connection string and the remote would have another. Is this how most people handle this environment? What is best practice?

In previous scratch developments, I added a test for a local connection (normally based on the url or IP) that would feed the connection string based on where the application was running.

I know there seems to be a production and development mode for Recess, is there a way to set up similar functionality in that I could have two different connection strings based on the context?

Again, I think I solved my own problem with the second solution, but I'd like some feedback on what is standard or best practice for a situation like this on Recess?

Thanks,
Jason Lally
0

#2 User is offline   Ned Schwartz Icon

  • Group: Members
  • Posts: 5
  • Joined: 28-September 09
  • LocationToronto, Ontario, CANADA

Posted 30 September 2009 - 03:16 PM

Hi Jason,

if you look at the top of recess-conf.php in the root of the install, you will see a line like:

RecessConf::$mode = RecessConf::DEVELOPMENT; 


you could programmaticly set this to either PRODUCTION or DEVELOPMENT.

for example:

RecessConf::$mode = ('devname.vhost' == $_SERVER['HTTP_HOST']) ? RecessConf::DEVELOPMENT : RecessConf::PRODUCTION;


Where 'devname.vhost' is the virtual host name of your recess app on your dev box.

Then in the rest of your recess-conf.php you can do checks for what mode RecessConf::$mode is and set your parameters accordingly:

if (RecessConf::$mode == RecessConf::DEVELOPMENT) {
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = 'devpassword';
} else {
  $dbhost = 'mysql.server.com';
  $dbuser = 'production_db_user';
  $dbpass = 'prodpassword';
}

RecessConf::$defaultDatabase = array('mysql:host=$dbhost;dbname=default_db', '$dbuser', '$dbpass');

RecessConf::$namedDatabases = array(
  'alternateDatasource' => array('mysql:host=$dbhost;dbname=another_db', '$dbuser', '$dbpass')
);


... Or whatever you need.

I hope that helps.
1

#3 User is offline   jasonlally Icon

  • Group: Members
  • Posts: 2
  • Joined: 30-September 09

Posted 01 October 2009 - 12:02 PM

Thanks! That works for me.

Jason
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users