0

I'm using a small CI codebase to run a simple feature in a larger codebase (a mix of Zend and Syfmony).

That master system uses a bootstrap file to set various global variables that I've accessed by creating a library file. it all works great and I can access the parent system, functions and global vars within my CI app.

BUT... That parent system stores DB connection info in sever related override files (So if code is deployed on server test.server, then config file test.server is loaded, and all relevant vars are set to that server.

What I need to do is tell my DB config file to access those vars. OR, in my model, set hostname, user and pass vars.

I've tried:

$this->db->hostname = GLOBAL_VAR_HOSTNAME;

but that is not working.

So can I pass any data from my library file into a config file, so I can set:

$db['default'] = array(
'hostname' => GLOBAL_VAR_HOSTNAME,
'username' => GLOBAL_VAR_USERNAME,

etc etc

Setting up all the DB info in the standard database config file as new servers are added all the time and they tech leads want to use the existing system for sharing vars.

I'm going for a coffee...

1 Answer 1

1

You can setup manual connections like this:

$this->load->database(array(
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'ci',
    'dbdriver' => 'mysqli',
));

var_dump($this->db->get('posts')->result());

Or you can create another connection completly:

$database = $this->load->database(array(
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'mydb',
    'dbdriver' => 'mysqli',
), TRUE);

var_dump($database->get('posts')->result());
Sign up to request clarification or add additional context in comments.

3 Comments

And this is set in the MODEL file?
'hostname' => GLOBAL_VAR_HOSTNAME,
Yes, you can put this in your model's constructor

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.