Welcome Guest, Not a member yet? Register   Sign In
using args[] to tell which server?
#1

I want to run my app either on the remote server or my localhost. To start it on my localhost I start the Apache and then type localhost in the browser window.  To start it on the server I type 54.152.xxx.9/sub_crud on the browser address bar. In my database.cfg I have 


if ($_SERVER['DOCUMENT_ROOT']="localhost") {
   $db['default'] = array(
       'dsn' => '',
       'hostname' => 'localhost',
       'username' => 'root',
       'password' => 'xxxx',  
       'database' => 'substantiator',
       'dbdriver' => 'mysqli',
       'dbprefix' => '',
       'pconnect' => FALSE,
       'db_debug' => (ENVIRONMENT !== 'production'),
       'cache_on' => FALSE,
       'cachedir' => '',
       'char_set' => 'utf8',
       'dbcollat' => 'utf8_general_ci',
       'swap_pre' => '',
       'encrypt' => FALSE,
       'compress' => FALSE,
       'stricton' => FALSE,
       'failover' => array(),
       'save_queries' => TRUE
   );
}
else {

   $db['default'] = array(
       'dsn' => '',
       'hostname' => 'localhost',
       'username' => 'root',
       'password' => 'xxxx',
       'database' => 'substantiator',
       'dbdriver' => 'mysqli',
       'dbprefix' => '',
       'pconnect' => FALSE,
       'db_debug' => (ENVIRONMENT !== 'production'),
       'cache_on' => FALSE,
       'cachedir' => '',
       'char_set' => 'utf8',
       'dbcollat' => 'utf8_general_ci',
       'swap_pre' => '',
       'encrypt' => FALSE,
       'compress' => FALSE,
       'stricton' => FALSE,
       'failover' => array(),
       'save_queries' => TRUE
   );


I also have this in my config.cfg
if ($args[0]="localhost") {
   $config['base_url'] = 'http://localhost//';
} else {
   $config['base_url']='http://54.152.xxx.9/sub_crud/';

}

For some reason, the localhost database seems to always load. It also seems that DOCUMENT_ROOT is unreliable and seems to be set to localhost even though I am using the 54.152.xxx.9/sub_crud in the browser. Is there a better way to do this? The passwords for the databases on the two servers are different. 
proof that an old dog can learn new tricks
Reply


Messages In This Thread
using args[] to tell which server? - by richb201 - 09-13-2018, 01:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB