Hook_schema and multiple databases Possible Duplicate:
  How do I specify in which database my schema should be created?  




I would like to create an entity module which discuss with another Drupal database.

In my module.install, this is ok :

db_set_active('otherdb');
if (!db_table_exists('mytable')) {
$result = db_query("CREATE TABLE mytable (
     id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
     title VARCHAR(255)
   );");
drupal_set_message("LOG :Creation of table mytable ok");
}
db_set_active();


but this can't be done with hook_schema  :

$schema['mytable'] = array (
'description' =&gt; 'The main store for our entity',
'fields' =&gt; array(
  'mytable_id' =&gt; array(
    'description' =&gt; 'Primary key for our table of mytable',
    'type' =&gt; 'serial',
    'unsigned' =&gt; TRUE,
    'not null' =&gt; TRUE,
  ),
  'title' =&gt; array(
    'description' =&gt; 'The mytable title',
    'type' =&gt; 'varchar',
    'length' =&gt; '255',
    'not null' =&gt; TRUE
  ),
),
'primary key' =&gt; array('mytable_id'),
);
db_set_active('otherdb');
return $schema;


Any ideas ?
I think another angle to attack the problem would be to implement hook_schema the normal way, as if there was only one database. And then tell Drupal to use another database for some tables in settings.php. Your module will not have to be run on seperate databases and all that external database stuff is taken care of by Drupals database layer.