使用codeigniter从第3个数据库访问多个数据库访问数据

时间:2015-05-21 08:54:48

标签: database codeigniter

我正在使用codeigniter。我想在我的项目中使用3个数据库。我将database.php文件设置为us,

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'marketer_fp';
$db['default']['password'] = 'xxxxx';
$db['default']['database'] = 'marketer_fpr';
$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;

$db['wpdb']['hostname'] = "localhost";
$db['wpdb']['username'] = "marketer_fprr";
$db['wpdb']['password'] = "yyyy";
$db['wpdb']['database'] = "marketer_mark";
$db['wpdb']['dbdriver'] = "mysql";
$db['wpdb']['dbprefix'] = "";
$db['wpdb']['pconnect'] = FALSE;
$db['wpdb']['db_debug'] = TRUE;
$db['wpdb']['cache_on'] = FALSE;
$db['wpdb']['cachedir'] = "";
$db['wpdb']['char_set'] = "utf8";
$db['wpdb']['dbcollat'] = "utf8_general_ci";


$db['wpfashn']['hostname'] = "localhost";
$db['wpfashn']['username'] = "marketer_fprr";
$db['wpfashn']['password'] = "yyyy";
$db['wpfashn']['database'] = "marketer_fah";
$db['wpfashn']['dbdriver'] = "mysql";
$db['wpfashn']['dbprefix'] = "";
$db['wpfashn']['pconnect'] = FALSE;
$db['wpfashn']['db_debug'] = TRUE;
$db['wpfashn']['cache_on'] = FALSE;
$db['wpfashn']['cachedir'] = "";
$db['wpfashn']['char_set'] = "utf8";
$db['wpfashn']['dbcollat'] = "utf8_general_ci";

第二个和第三个数据库具有相同的用户名和密码。 在控制器中,内部构造函数这三个数据库被调用。

        $this->db3 =$this->load->database('wpfashn', TRUE);
        $this->db2 =$this->load->database('wpdb', TRUE);
        $this->db =$this->load->database('default', TRUE);

在另一个函数内部编写一个查询,该查询应该使用数据库3执行。

$check=$this->db3->query("select * from  mm_use_dat where wp_user_id='2'");

的print_r($入住>结果()); 即使数据库中存在值,此查询也会返回一个空数组。应该是什么问题?请帮我找一个解决方案!

0 个答案:

没有答案