Dynamic Select Query On Another DB Is there a straightforward solution to do the dynamic select statements against another database on the same server? I fooled around with attempting to modify the documentation example to no avail.

// Create an object of type SelectQuery and directly 
// add extra detail to this query object: a condition, fields and a range
$query = db_select('custom_module_db', 'table_foo')
  -&gt;condition('table_foo.id', 0, '&gt;')
  -&gt;fields(array('id', 'field_1', 'field_2'));

$result = $query-&gt;execute();


My current database setup looks like this

AWS RDS Server 
 -&gt;production drupal database
   -&gt;Drupal Installation Tables
 -&gt;custom module database
   -&gt;Custom Module Tables


Clarification the below method works fine against the custom module database without adding a specific settings reference for that particular database. 

So was looking to see if I can use the db_select() function in the same way as db_query() without needing to go in and add another database reference.

 $data_set = db_query($query='SELECT * FROM custom_module.db.table_foo WHERE ......)


Then grabbing the resultset by

$results = $this-&gt;WeightedAverageFunction($data_set-&gt;fetchAll())
Add external database name in settings.php(../sites/all/default/settings.php) file of your project. You can set databse in settings.php as follows:  

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

  'external' =&gt; 
  array (
    'default' =&gt; 
    array (
      'database' =&gt; 'external_db',
      'username' =&gt; 'root',
      'password' =&gt; '',
      'host' =&gt; 'localhost',
      'port' =&gt; '8080',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ),
  ),
);


And you can directly add your query in files.