How to choose multisite instance inside script running from main Drupal directory?
Since you know the database name, you can dynamically set a database name which you will call with db_set_active().

This is copy/pasted from the link below.

  $other_database = array(
      'database' =&gt; 'databasename',
      'username' =&gt; 'username', // assuming this is necessary
      'password' =&gt; 'password', // assuming this is necessary
      'host' =&gt; 'localhost', // assumes localhost
      'driver' =&gt; '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.'));


More about this can be found here.