Can there be any function maintained to extract database configuration within my code, something similar to $db_user = drupal_get_dbuser(); $db_pass = drupal_get_dbpass();
...
...

The code with this is:

<?php
  global $db_url;
  $creds =  parse_url($db_url);
  print $creds['user'];
  print $creds['pass'];
  var_dump($creds);
?>

More in depth info and edge-cases are available by reading through the code of http://api.drupal.org/api/function/db_connect/6