CodeIgniter Forums
Accessing the Database Configuration Array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Accessing the Database Configuration Array (/thread-42431.html)



Accessing the Database Configuration Array - El Forum - 06-07-2011

[eluser]NotoriousWebmaster[/eluser]
I'm writing a utility app which allows the admin to perform tasks on different instances of the database by selecting the DB in the form (radio buttons). Based on this selection, the controller needs to load the model with the given DB's config array.

This DB config array is already defined in the database.php config file. Is there some way to access this array from the controller?

Thanks for your help,
- AAA


Accessing the Database Configuration Array - El Forum - 06-07-2011

[eluser]InsiteFX[/eluser]
CodeIgniter User Guide - Config Class

InsiteFX


Accessing the Database Configuration Array - El Forum - 06-07-2011

[eluser]NotoriousWebmaster[/eluser]
Thx for the quick reply InsiteFX. In fact, I did dump the $this->config object from the controller to see if it contained what I was looking for. It didn't.

But reviewing the docs for the config class I'm thinking I could save the db array in the config/database.php file, to the config class. Then access it from the controller.

This'll work for now. Please let me know if there's a better way to do this.

Thx again,
- AAA


Accessing the Database Configuration Array - El Forum - 06-07-2011

[eluser]InsiteFX[/eluser]
Yep, I just checked they are including the database.php file!

You could include the database.php file yourself and then access.
Code:
include(APPPATH.'config/database.php')

InsiteFX