0

Not sure if this is the right way to do things, but was wondering if anyone had some ideas or advice on how to achieve this.

I want to create a subdomain called demo.mysite.com

and i want this to load my codeigniter application which is in public_html, however if the sub domain is demo. then it loads another database instead of the main one

The following is from config/database.php

$db['default']['username'] = "main";
$db['default']['password'] = "password!";
$db['default']['database'] = "mainsite";

The reason I want to do this is i still make changes to my site and dont want to have to keep copying my entire site into a demo folder everytime i make a change.

Hope this makes sense

0

2 Answers 2

1

Create two subdirectories in config dir

aplication
  config
     site1
     site2

Move diiferent files of config dir to that subdirs

In index.php set ENVIRONMENT constant to site1 for one site and site2 for another. To set correct error reporting, add site1 and site2 into switch operator below with a desired state of reporting

define('ENVIRONMENT', 'site1');

switch (ENVIRONMENT)
{
    case 'development':
    case 'site1':
...

CI get config files from subdir named as ENVIRONMENT

Sign up to request clarification or add additional context in comments.

1 Comment

This is the best answer, since this is an environment thing, the configs should be separate. Not just the database ones but other things like cookies and stuff. Separate them with the environment folders is the best option.
0

In config database.php you may create different db groups, the one that already exists is the default group:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => '',
    'password' => '',
    'database' => '',
    ...

You can create another group with any name:

$db['another_group'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => '',
    'password' => '',
    'database' => '',
    ...

You can then connect to another database by using:

$this->load->database('another_group', TRUE);

You will find more details in the docs here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.