我是codeigniter的初级,我想做的是连接多个数据库来检索数据库数据,但它对我不起作用,请保留给我404错误页面
这是我的代码
配置/ database.php中
$active_group = 'qm';
$active_record = TRUE;
$db['qm']['hostname'] = '192.168.0.128';
$db['qm']['username'] = 'callcenter';
$db['qm']['password'] = 'ca11c3nt3r';
$db['qm']['database'] = 'qm';
$db['qm']['dbdriver'] = 'mysql';
$db['qm']['dbprefix'] = '';
$db['qm']['pconnect'] = TRUE;
$db['qm']['db_debug'] = TRUE;
$db['qm']['cache_on'] = FALSE;
$db['qm']['cachedir'] = '';
$db['qm']['char_set'] = 'utf8';
$db['qm']['dbcollat'] = 'utf8_general_ci';
$db['qm']['swap_pre'] = '';
$db['qm']['autoinit'] = TRUE;
$db['qm']['stricton'] = FALSE;
/* call contact detail table */
$active_group = "reportcallcenter";
$active_record = TRUE;
$db['reportcallcenter']['hostname'] = '192.168.0.128';
$db['reportcallcenter']['username'] = 'callcenter';
$db['reportcallcenter']['password'] = 'ca11c3nt3r';
$db['reportcallcenter']['database'] = 'reportcallcenter';
$db['reportcallcenter']['dbdriver'] = 'mysql';
$db['reportcallcenter']['dbprefix'] = "";
$db['reportcallcenter']['pconnect'] = TRUE;
$db['reportcallcenter']['db_debug'] = TRUE;
$db['reportcallcenter']['cache_on'] = FALSE;
$db['reportcallcenter']['cachedir'] = "";
$db['reportcallcenter']['char_set'] = "utf8";
$db['reportcallcenter']['dbcollat'] = "utf8_general_ci";
$db['reportcallcenter']['swap_pre'] = '';
$db['reportcallcenter']['autoinit'] = TRUE;
$db['reportcallcenter']['stricton'] = FALSE;
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Qm extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->permission->is_logged_in();
//load model
$this->load->helper('url');
$this->load->model('callcontactsdetails_model');
$this->load->database('qm', TRUE);
$this->load->database('reportcallcenter', TRUE);
}
function qm_form()
{
$data = array();
$data['page'] = 'qm_form';
if($query = $this->callcontactsdetails_model->get_all())
{
$data['recordings_record'] = $query;
}
$data['main'] = 'qm/qm_form';
$data['js_function'] = array('qm');
$this->load->view('template/template',$data);
}
}//end of class
?>
模型(我使用My_model)
<?php
class Callcontactsdetails_model extends MY_Model {
protected $_table = 'callcontactsdetails';
protected $primary_key = 'id';
}
?>
我的屏幕返回结果 任何想法如何解决我的问题或我做的任何错误?
答案 0 :(得分:1)
像这样加载你的数据库
$this->db_report = $this->CI->load->database('reportcallcenter', TRUE);
假设'qm'db将被设置为默认值
或者您可以尝试这样
$DB1 = $this->load->database('qm', TRUE);
$DB2 = $this->load->database('reportcallcenter', TRUE);
然后你可以使用像
$DB1->query();
$DB1->result();
和
$DB2->query();
$DB2->result();
在您的情况下尝试
if($query = $DB2->get_all())
{
$data['recordings_record'] = $query;
}