我正在四處尋找這個問題!但沒有什麼真正幫助解決這個問題。CodeIgniter模型類中的數據庫調用
我總是得到以下錯誤: 「致命錯誤:調用一個成員函數查詢()一個非對象」
我有以下控制器:
<?php
class Station extends CI_Controller {
function __construct($params=array()) {
parent::__construct();
session_start();
$this->load->library('parser');
$this->load->helper(array('form', 'url'));
}
public function index() {
$this->tpl_data['location'] = $this->stationmodel->getLocations()->all;
$_SESSION['location'] = $this->tpl_data['location'];
$this->load->view('station', $this->tpl_data);
}
}
>
而以下型號:
<?php
class StationModel extends CI_Model {
function __construct() {
parent::__construct();
}
public function getLocations() {
$query = $this->db->query("SELECT * FROM location WHERE City_IATA = 'MUC'");
var_dump($query);
// Just for test purposes!
foreach($query->result() as $row) {
echo $row->Location_Name_DE . '<br />';
}
}
}
>
在我autoload.php我加載數據庫模塊:
$autoload['libraries'] = array('database');
而且當我嘗試在控制器中直接加載數據庫MODUL我會得到同樣的錯誤。
我database.php中:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '****';
$db['default']['database'] = 'comvel';
$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;
任何人都可以幫我嗎?
在此先感謝!
什麼返回var_dump? – Patroklo 2012-04-24 10:42:25
你檢查了你的數據庫設置嗎? – 2012-04-24 10:43:23
var_dump不會返回任何內容,導致它在var_dump之前死亡。 數據庫設置已檢查並罰款: -/ – Xederas 2012-04-24 11:09:49