问题描述
我在CodeIgniter中看到很多方法/教程来连接多数据库?仍然远离我。有人提供我在CI连接多数据库。这是我的使用方式,我被发现在一个博客。 pardon me,我不认识博客地址。
I see a lot of method/tutorial to connect multi database in CodeIgniter? Still far far away with me. Some one provide me to connect multi database in CI. This is my using way i was found it in a blog. pardon me, i don't recognize the blog address.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'vk_global';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
//add alternate database settings
$db['wow']['hostname'] = 'localhost';
$db['wow']['username'] = 'root';
$db['wow']['password'] = 'root';
$db['wow']['database'] = 'auth';
$db['wow']['dbdriver'] = 'mysql';
$db['wow']['dbprefix'] = '';
$db['wow']['pconnect'] = TRUE;
$db['wow']['db_debug'] = TRUE;
$db['wow']['cache_on'] = FALSE;
$db['wow']['cachedir'] = '';
$db['wow']['char_set'] = 'utf8';
$db['wow']['dbcollat'] = 'utf8_general_ci';
$db['wow']['swap_pre'] = '';
$db['wow']['autoinit'] = TRUE;
$db['wow']['stricton'] = FALSE;
我用这个代码调用它
$DB2 = $this->load->database('auth',true);
并且我用此代码插入一个简单的行
and i was insert a simple row with this code
$this->$DB2->insert('events_grouptable',$data);
我收到此错误您指定了无效的数据库连接组。 $
解决方案
推荐答案
> load-> database('default',TRUE);
$ DB2 = $ this-> load-> database('wow',TRUE);
$DB1 = $this->load->database('default', TRUE);$DB2 = $this->load->database('wow', TRUE);
您需要设置要与哪个组使用哪个数据库,否则该替代不能工作
You need to set which db to use with which group otherwise the alternative does not work as
$active_group = 'default';
更多详情请参阅
这篇关于CodeIgniter MultiDatabse连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!