Codeigniter:无法在我的库中加载数据库。

问题描述:

当我尝试调用

When I try to call

$this->load->database();

产生以下错误在非对象上调用成员函数database()


自动加载数据库也无济于事...

当我尝试自动加载数据库时。

所有对数据库的调用,如

yields the following error `"Call to a member function database() on a non-object"
Autoloading the database doesnt help too...
when I try to autoload it.
all calls to database like

$this->db->get('people');

它说get方法未定义...

我不知道什么
where
任何人?

it says get method is undefined...
I have no clue what and where to start..
\ anyone ?

转到 application / config / autoload.php 并添加此

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

请确保在应用程序中连接设置正确/config/database.php

比在库中这样做

Class MyLib
{
    function getPeople(){
        $CI =   &get_instance();
        $query  =   $CI->db->get('people');
        return $query->result();
    }
}