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
Page 1 of 1
Maintaining two database connections through recess
#2
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:
you could programmaticly set this to either PRODUCTION or DEVELOPMENT.
for example:
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:
... Or whatever you need.
I hope that helps.
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.
Page 1 of 1

Sign In
Register
Help


MultiQuote