To Connect to MYSQL - How to access database array in setting.php I need to connect to my database in php file in drupal 7. Each time I move from local server to development server, I have to change my db and host. I have seen setting.php file which have array of database.

$databases = array (
  'default' =&gt; 
  array (
    'default' =&gt; 
    array (
      'database' =&gt; 'my_db',
      'username' =&gt; 'root',
      'password' =&gt; '',
      'host' =&gt; 'localhost',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ),
  ),
);


How do I aceess this database array in drupal 7 to use it connecting to database

$con = mysqli_connect('localhost','root','','my_db');


Thanks for Help
If you want to access the Drupal database from a standalone script.

Firstly, consider if you can put the PHP code in a Drupal module instead.
Secondly, consider bootstrapping Drupal in your PHP script  

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', '/var/www/drupal');

// Bootstrap to database level for db api
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);


You can then use the Drupal database API to query content from the Drupal database.

Thirdly, if connecting to a different database is required, consider defining the other database in settings.php and switching to a target database using db_set_active 

// Settings.php
$databases['default']['default'] = array(
  'driver' =&gt; 'mysql',
  'database' =&gt; 'drupal7',
  'username' =&gt; 'drupal_user',
  'password' =&gt; 'drupal_password',
  'host' =&gt; 'localhost',
  'prefix' =&gt; '',
);

$databases['other_database']['default'] = array(
  'driver' =&gt; 'mysql',
  'database' =&gt; 'other_database',
  'username' =&gt; 'other_database_user',
  'password' =&gt; 'other_database_password',
  'host' =&gt; 'localhost',
  'prefix' =&gt; '',
);


Then you can switch between databases with db_set_active

// Query other database
db_set_active('other_database');
// $query = db_select('my_table'); // e.g
// Return to default database
db_set_active();