Friday, 11 May 2012

Solution to the problem defining the multiple databases on CodeIgnieter

// Solution to the problem defining the multiple databases on config/database.php on CodeIgnieter
/** Defining Database 1 */
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'dbusername_1';
$db['default']['password'] = 'dbpassword_1';
$db['default']['database'] = 'database_1';
$db['default']['dbdriver'] = 'mysql';
/* ----------
------- */
$db['default']['stricton'] = FALSE;

/** Defining Database 2 */
$db['manage']['hostname'] = 'localhost';
$db['manage']['username'] = 'dbusername_2';
$db['manage']['password'] = 'dbpassword_2';
$db['manage']['database'] = "database_2";
$db['manage']['dbdriver'] = "mysql";
/* ----------
------- */
$db['default']['stricton'] = FALSE;

/** Defining Database 3 */
$db['admin']['hostname'] = "localhost";
$db['admin']['username'] = "dbusername_3";
$db['admin']['password'] = "dbpassword_3";
$db['admin']['database'] = "database_3";
$db['admin']['dbdriver'] = "mysql";
/* ----------
------- */
$db['default']['stricton'] = FALSE;


PS: Please note that, all the databases username/password needs to be unique, if
they have shared the same username/password, then, there may be problem.
Actually, when I tried to use the same username/password for different databases,
I have found that the CodeIgniter is overriding my databases and I have solved it
by assigning unique username/password to each database.

Well, I am not sure, whether its CodeIgniter drawback or not. And, I thought it
would be helpful to share with you as well.

Cheers!

No comments:

Post a Comment

Please post any queries and comments here.