Welcome Guest, Not a member yet? Register   Sign In
Multiple database prefixes
#1

[eluser]Unknown[/eluser]
Hi,

I am currently investigating the feasibility of moving an existing application to codeigniter.

One issue I have identified is that the existing database of the application uses more than one table prefix.

Prefixes seem to be configured with $db['default']['dbprefix'] = '';

The application in question uses a edu_ prefix for all tables native to the application itself and it also has a number of tables prefixed with ext_ for tables which store data from non-native sources.

I realize I can get around this with db->query but I was wondering if there's another option if I want to use the active record pattern.
#2

[eluser]larsonator[/eluser]
Hi,
while i have not used table prefixes myself, it looks as though you should be ok with using two Database configurations. Each with the same connections strings, but with different db_prefixes.

Eg.
Code:
$active_group = 'edu'
$active_record = TRUE;

$db['edu']['hostname'] = DB_HOST;
$db['edu']['username'] = DB_USER;
$db['edu']['password'] = DB_PASS;
$db['edu']['database'] = DB_PRIMARY;
$db['edu']['dbdriver'] = 'mysql';
$db['edu']['dbprefix'] = 'edu_';

$db['ext']['hostname'] = DB_HOST;
$db['ext']['username'] = DB_USER;
$db['ext']['password'] = DB_PASS;
$db['ext']['database'] = DB_PRIMARY;
$db['ext']['dbdriver'] = 'mysql';
$db['ext']['dbprefix'] = 'ext_';

you can load the databases like so:
Code:
$this->load->database('ext', true);
$this->load->database('edu', true);

Correct me if there is a better way of doing so by all means, but thats one way i see it being done.
#3

[eluser]Unknown[/eluser]
OK, Thank you for your prompt response. I will try out this method.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB