Welcome Guest, Not a member yet? Register   Sign In
How to select one of the database groups
#1

[eluser]Unknown[/eluser]
Hi all,

in config/database.php I have to define a couple of database connections:

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "whatever";
.....
$db['special']['hostname'] = "localhost";
$db['special']['username'] = "root";
$db['special']['password'] = "";
.....

etc.

Now, is there a way of getting an array (or something else) that gives me the names of all the used identifiers? In the example above I would expect "default" and "special" as the result. Unfortunately you cannot access $db directly...

Thanx!
#2

[eluser]Dam1an[/eluser]
You can just include the config file, and then access the $db array like so
Code:
include APPPATH.'config/database.php';
foreach($db as $k=>$v) {
    echo $k.'<br />';
}
#3

[eluser]richthegeek[/eluser]
Couldn't you also use
Code:
keys($db)
to return an array?
#4

[eluser]Unknown[/eluser]
Thanx guys, that worked really great. Including the app path gives access to the db data. then it's totally easy...

Btw., you meant array_keys, right? :-)
#5

[eluser]Dam1an[/eluser]
Another day, another new function to add to my growing knowledge Smile
#6

[eluser]richthegeek[/eluser]
yep sorry, I was thinking of key() for some reason.




Theme © iAndrew 2016 - Forum software by © MyBB