我有两个需要连接的数据库,可以在我编写的控制器和库中完成。出于某种奇怪的原因(我假设我只是在这里遗漏了一些简单的东西)我突然无法让它在模型中工作。我已阅读 CI 用户指南中的数据库类。
我尝试在加载 pew ($this->pew =& $this->load->database('pew', TRUE)) 时引用 $pew 无济于事。
有什么想法、建议吗?谢谢!
错误
PHP Fatal error: Call to a member function query() on a non-object in
/Sites/CI/nyan/application/models/pewpewmodel.php on line 15
15号线
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
数据库.php:
$active_group = 'nyan';
$active_record = TRUE;
$db['nyan']['hostname'] = 'catcatcat';
$db['nyan']['username'] = 'mew';
$db['nyan']['password'] = 'meow';
$db['nyan']['database'] = 'meow';
$db['nyan']['dbdriver'] = 'mysql';
$db['pew']['hostname'] = 'jujubees';
$db['pew']['username'] = 'qwop';
$db['pew']['password'] = 'qwop';
$db['pew']['database'] = 'nom';
$db['pew']['dbdriver'] = 'mssql';
模型 pewpewmodel.php
private $pew;
function __construct()
{
parent::__construct();
$this->pew = $this->load->database('pew', TRUE);
}
function get_forms_by_date($id = NULL, $Year = NULL, $Month = NULL, $Day = NULL)
{
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing
}
控制器 nomnom.php
public function index()
{
$this->load->model('pewmodel');
$data['Forms'] = $this->pewmodel->get_forms_by_date($this->session->userdata('Username'), date('Y'), date('n'), date('j'));
$this->load->view('common/header', $data['Forms']);
$this->load->view('home/index');
$this->load->view('common/footer');
}
查看 index.php
<pre>
<?php print_r($Forms); ?>
</pre>