Call to a member function insert() on a non-object
A PHP Error was encounteredSeverity: NoticeMessage: Undefined property: Test::$db
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function insert() on a non-object in D:\AppServ\www\MT\application\models\mtest.php on line 16
怎么重新下载安装配置CI,都是这样,救命啊!!!
你加载了db没有哦,好好看看手册呀 加载了db?
model文件
<?php
class Mtest extends CI_Model {
function __construct()
{
parent::__construct();
}
function add(){
$name=$this->input->post('name');
$age=$this->input->post('age');
$address=$this->input->post('address');
$data = array(
'name' => '$name',
'age' => '$age',
'address' =>'$address'
);
$this->db->insert('add',$data);
}
}
?> 有问题? 版主问的应该是你的database.php配置好了没啊吧! 表示database没有错误,请看:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '123456';
$db['default']['database'] = 'test';
$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; 多谢回复! 呃~有同有加载数据库啦
就是一般在autoload.php里
$autoload['libraries'] = array('database');
加载数据库类! 拜谢!
我试试! 我走了。第一次用框架就这样杯具!
页:
[1]
2