n Drupal 7, first construct a database connection array, then connect to it to Drupal's front-controller, then execute queries using D7's database abstraction layer.
<?php
$other_database = array(
'database' => 'databasename' ,
'username' => 'username' , // assuming this is necessary
'password' => 'password' , // assuming this is necessary
'host' => 'localhost' , // assumes localhost
'driver' => 'mysql' , // replace with your database driver
);
// replace 'YourDatabaseKey' with something that's unique to your module
Database :: addConnectionInfo ( 'YourDatabaseKey' , 'default' , $other_database );
db_set_active ( 'YourDatabaseKey' );
// execute queries here
db_set_active (); // without the paramater means set back to the default for the site
drupal_set_message ( t ( 'The queries have been made.' ));
?>