在codeigniter上使用Erorr多个数据库

时间:2017-05-03 09:43:42

标签: php codeigniter mysqli

我正在尝试使用多个数据库构建一个项目我在项目中使用了3个数据库,有时应用程序正常运行但是突然出现了关于数据库出错的警告错误?

Unable to connect to your database server using the provided settings.

Filename: C:/xampp/htdocs/sbc-portal/system/database/DB_driver.php

Line Number: 436

1 个答案:

答案 0 :(得分:2)

用于辅助数据库添加以下代码

$db['otherdb']['hostname'] = "localhost";
$db['otherdb']['username'] = "root";
$db['otherdb']['password'] = "";
$db['otherdb']['database'] = "other_database_name";
$db['otherdb']['dbdriver'] = "mysql";
$db['otherdb']['dbprefix'] = "";
$db['otherdb']['pconnect'] = FALSE;
$db['otherdb']['db_debug'] = FALSE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = "";
$db['otherdb']['char_set'] = "utf8";
$db['otherdb']['dbcollat'] = "utf8_general_ci";
$db['otherdb']['swap_pre'] = "";
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;

然后连接到辅助数据库

$otherdb = $this->load->database('otherdb', TRUE);
$test= $otherdb->get('test');
希望它有效。