When you want to connect other external database from your current project:

$conf =& JFactory::getConfig();
$host 		= '192.168.1.2'; //replace your IP or hostname
$user 		= 'db_user'; //database user
$password 	= 'db_pass';//database password
$database	= 'db_name'; //database name
$prefix 	= 'jos_'; //prefix if any else just give any random value
$driver 	= 'mysql'; //here u can also have ms sql database driver, postgres, etc
$debug 		= $conf->getValue('config.debug');
$options	= array ( 'driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );

$db =& JDatabase::getInstance( $options );

//Do the rest of process (queries) like usual