I am contemplating a patch that would allow db_prefix to specify a default table prefix for multiple databases as specified in db_url. If I have

$db_url['default'] = 'mysql://dbuser1:dbpass1@localhost/db1'
$db_url['db2'] = 'mysql://dbuser2:dbpass2@localhost/db2'

I want to be able to do something like

$db_prefix['default']['default'] = 'myprefix_';
$db_prefix['default']['db2'] = '';

This would prevent me from having to do

$db_prefix = array(
 'default' => 'myprefix_',
 'mydb2table1' => '',
 'mydb2table2' => '',
 'mydb2tableN' => '',
);

Comments

ttkaminski’s picture

I was hoping that drupal supported a prefix on a per db_url basis, but it isn't supported in drupal <= 6.x. Has this been implemented for 7.x yet?? I would rather have the url and prefix specified as follows:

$db_info['default'] = array(
                       'url' =>'mysql://dbuser1:dbpass1@localhost/db1',
                       'prefix' => 'myprefix1_'
);

$db_info['db2'] = array(
                       'url' =>'mysql://dbuser2:dbpass2@localhost/db2',
                       'prefix' => 'myprefix2_'
);

I am very surprised that this hasn't already been implemented since the current implementation in 6.x assumes that the prefix is applied to all db_url connections which is simply wrong.

berdir’s picture

Status: Active » Closed (duplicate)

There is an issue for this at #195416: Table prefixes should be per database connection which unfortunately has been postponed to D8.

(Sorry for pinging the participants, I'm trying to clean up a few old
issues)