Don't mess with the $DB global (you will break things), but you can create an instance of the moodle_database class (or an appropriate subclass like mysqli_native_moodle_database) and use that to query other databases.
Perhaps something like this:
$extdb = new mysql_native_moodle_database(true); // true says that it's an external database, so don't use Moodle's prefix
$extdb->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, 'neighbor', '');