|
本帖最后由 helloworldok 于 2010-5-24 15:17 编辑
各位大大:
我刚开始学习codeIgniter,想连接mysql数据库,出了问题,看手册没有搞明白
在database.php中添加:
$db['alphatest']['hostname'] = "localhost";
$db['alphatest']['username'] = "root";
$db['alphatest']['password'] = "";
$db['alphatest']['database'] = "alphatest";
$db['alphatest']['dbdriver'] = "mysql";
$db['alphatest']['dbprefix'] = "";
$db['alphatest']['pconnect'] = TRUE;
$db['alphatest']['db_debug'] = TRUE;
$db['alphatest']['cache_on'] = FALSE;
$db['alphatest']['cachedir'] = "";
$db['alphatest']['char_set'] = "utf8";
$db['alphatest']['dbcollat'] = "utf8_general_ci";
///////////////////////////////////////////////////////////
$db['bugs']['hostname'] = "localhost";
$db['bugs']['username'] = "root";
$db['bugs']['password'] = "";
$db['bugs']['database'] = "bug38";
$db['bugs']['dbdriver'] = "mysql";
$db['bugs']['dbprefix'] = "";
$db['bugs']['pconnect'] = TRUE;
$db['bugs']['db_debug'] = TRUE;
$db['bugs']['cache_on'] = FALSE;
$db['bugs']['cachedir'] = "";
$db['bugs']['char_set'] = "lant1";
$db['bugs']['dbcollat'] = "utf8_general_ci";
////////////////////////////////////////////////////
然后就不知道怎么连接这两个数据库了。
手册上说:
如果你需要同时连接多于一个的数据库,你可以用以下方式来实现:
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
注意:改变 "group_one" 和 "group_two" 为你指定了连接属性的组名 (或者通过上边说过的连接数组的数组名)。
这个group_one应该怎么写呢?
我是这么做的
在database.php中加入
$group_bugs='bugs';
$group_alpha='alphatest';
控制器中的代码如下:
$bugs=$this->load->database('group_bugs');
$alphatest=$this->load->database('group_alpha');
但是提示错误:
An Error Was Encountered
You have specified an invalid database connection group. |
|