带有CodeIgniter的insert()上的致命数据库错误

时间:2015-09-22 09:11:06

标签: php codeigniter

我收到此错误,但我不知道该怎么做:

  

遇到PHP错误    严重性:通知
   消息:未定义属性:Welcome :: $ db
   文件名:core / Model.php
   行号:52
   致命错误:在第38行的C:\ xampp \ htdocs \ site \ application \ models \ account_model.php中调用null上的成员函数insert()

控制器:

public function register()//function register in the controller
{
        $this->load->model('account_model');
        $this->account_model->create_account(); 
}

型号:

function create_account()//function insert.
{
    $insertdata = array('id' =>'',
        'firstname' => $this->input->post('fname'),
        'username' => $this->input->post('email'),
        'username' => $this->input->post('username'),
        'password' => $this->input->post('pass'),
        'role' => '1',
        'status' => 'Active');

    $insert = $this->db->insert('account', $insertdata);
    return $insert; 
}

2 个答案:

答案 0 :(得分:1)

您需要将数据库库加载到自动加载配置文件中,您已经完成了吗?

它位于../application/config/autoload.php,搜索:

$autoload['libraries'] = array();

并添加如下数据库:

$autoload['libraries'] = array('database');

答案 1 :(得分:0)

config/autoload.php中,加载database

$autoload['libraries'] = array('database');
相关问题