|
我接了一个项目,之前,MYSQL数据库已经搭建、设计完成。这个项目一共建了3个数据库,分别是A、B、C三个
我用操作手册上提供的连接多个数据库的方法进行连接,每次都不成功。(在本地PHP环境,远程连接数据库)
首先,我在autoload.php中加载 $autoload['libraries'] = array("session","database");
其次,在database.php中把三个数据库的配置信息添加在了里面:
PHP复制代码
$active_group = 'bbb';
$active_record = TRUE;
$db['aaa']['hostname'] = '125.124.12.11';
$db['aaa']['username'] = 'root';
$db['aaa']['password'] = 'abc123';
$db['aaa']['database'] = 'aaa';
$db['aaa']['dbdriver'] = 'mysql';
$db['aaa']['dbprefix'] = '';
$db['aaa']['pconnect'] = FALSE;
$db['aaa']['db_debug'] = TRUE;
$db['aaa']['cache_on'] = FALSE;
$db['aaa']['cachedir'] = '';
$db['aaa']['char_set'] = 'utf8';
$db['aaa']['dbcollat'] = 'utf8_general_ci';
$db['aaa']['swap_pre'] = '';
$db['aaa']['autoinit'] = TRUE;
$db['aaa']['stricton'] = FALSE;
$db['bbb']['hostname'] = '125.124.12.11';
$db['bbb']['username'] = 'root';
$db['bbb']['password'] = 'abc123';
$db['bbb']['database'] = 'bbb';
$db['bbb']['dbdriver'] = 'mysql';
$db['bbb']['dbprefix'] = 'db_';
$db['bbb']['pconnect'] = FALSE;
$db['bbb']['db_debug'] = TRUE;
$db['bbb']['cache_on'] = FALSE;
$db['bbb']['cachedir'] = '';
$db['bbb']['char_set'] = 'utf8';
$db['bbb']['dbcollat'] = 'utf8_general_ci';
$db['bbb']['swap_pre'] = '';
$db['bbb']['autoinit'] = TRUE;
$db['bbb']['stricton'] = FALSE;
$db['ccc']['hostname'] = '125.124.12.11';
$db['ccc']['username'] = 'root';
$db['ccc']['password'] = 'abc123';
$db['ccc']['database'] = 'ccc';
$db['ccc']['dbdriver'] = 'mysql';
$db['ccc']['dbprefix'] = 'db_';
$db['ccc']['pconnect'] = FALSE;
$db['ccc']['db_debug'] = TRUE;
$db['ccc']['cache_on'] = FALSE;
$db['ccc']['cachedir'] = '';
$db['ccc']['char_set'] = 'utf8';
$db['ccc']['dbcollat'] = 'utf8_general_ci';
$db['ccc']['swap_pre'] = '';
$db['ccc']['autoinit'] = TRUE;
$db['ccc']['stricton'] = FALSE;
复制代码
再次,建模
PHP复制代码
class User_info_Model extends CI_Model{
private $aaa;
public function __construct()
{
parent::__construct();
$this->aaa = $this->load->database("aaa",TRUE);
}
public function get_list($order,$limit=7)
{
$sql = "...";
$result = $this->aaa->query($sql);
return $result->result_array();
}
public function get_last()
{
$sql = "...";
$result = $this->aaa->query($sql);
return $result->result_array();
}
}
复制代码
控制器,我正常加载model,
PHP复制代码
$this->load->model("User_info_Model","user");
$data['order_acount'] = $this->user->get_list($order);
$this->load->view("index",$data);
复制代码
系统提示我,无法加载数据库bbb。
或者:Your application/config/database.php file does not appear to contain a valid configuration array.
怎样调试都是如此。最后,我把远程数据库导出。在本地WAMP环境下的MYSQL服务器上,重新搭建了一下,只按照本地服务器的配置修改了database.php文件。其他都未作任何改动,问题就没有了,似乎已经解决了。。。。。。。。
我的问题是: 连接多数据库,是不是和MYSQL的版本,环境配置等有关系呢?
PS:远程数据库的版本比我本地的版本要高服务器版本: 5.5.32 VS 服务器版本: 5.5.8-log协议版本: 10
|
|