How to get the current active DB in Drupal 6? You can easily print out the current db_name, by printing out $db_url. But there is no clear way in the API that allows you to print out the "key" for the active db. So I have two dbs, namely "testing" and "default". What php code can I run to find out whether I am currently using the "testing" db, or the "default" db?

I'm bascially looking for the inverse of "db_set_active". So If I do this:

db_set_active("default");


What can I call directly after it to find out which is the current active db (i.e. "default")?
Doesn't look like drupal allows it inherently, so I'm posting my hack in the meantime. I'm open to any suggestions on improving this:

global $db_url;
$activeDBName = db_result(db_query('select database()'));
$mode = '';
foreach ($db_url as $key =&gt; $url) {
    if(strpos($url, $activeDBName) !== FALSE) {
        $mode = $key;
    }
}


$mode will then be whatever the active db is.