CI: how to configure multi-database access and ci Database Access
This example describes how to configure multi-database access for CI. We will share this with you for your reference. The details are as follows:
1. Modify the datebase. php file:
$db['XXX']['pconnect'] = TRUE;
Modify:
$db['XXX']['pconnect'] = FALSE;
2. Copy the original database link definition, as shown in the current
$ Db ['bbs '] ['hostname'] = 'your database IP address'; $ db ['bbs'] ['username'] = 'link username '; $ db ['bbs '] ['Password'] = 'database connection password'; $ db ['bbs'] ['database'] = 'database name '; $ db ['bbs '] ['dbdriver'] = 'mysql'; $ db ['bbs '] ['dbprefix'] = 'cg _'; $ db ['bbs '] ['pconnect'] = FALSE; $ db ['bbs '] ['db _ debug'] = TRUE; $ db ['bbs '] ['cache _ on'] = FALSE; $ db ['bbs'] ['cachedir'] = ''; $ db ['bbs '] ['Char _ set'] = 'utf8'; $ db ['bbs'] ['dbcollat'] = 'utf8 _ general_ci '; $ db ['bbs '] ['SWAp _ pre'] = ''; $ db ['bbs'] ['autoinit '] = TRUE; $ db ['bbs '] ['stricton'] = FALSE;
The rest do not need to be modified, and then load the constructor in your controller:
Function _ construct () {parent ::__ construct (); $ this-> XXX = $ this-> load-> database ('xxx', TRUE ); // Note: Here XXX represents the bbs above. You can change it to bbs}
Usage:
$ Query = $ this-> bbs-> query ($ SQL); // same as before, here, $ this-> XXX is used as your defined bbs $ rs = $ query-> result ();