CodeIgniter and autoloading the database library

后端 未结 7 932
小鲜肉
小鲜肉 2021-01-21 04:19

I\'ve got an issue connecting to the database with CodeIgniter.

In the model, if I do

$this->load->database();

then a query such

7条回答
  •  -上瘾入骨i
    2021-01-21 04:36

    This is just an alternative if you still can't resolve the issue. Just extend the CI_Model and auto load the database library in the constructor. Then you can just make all other models inherit from that base class.

    Example:

    load->database();
             }
         }
    

    And the all others will start like :

      

    This method has the other benefit that you don't have to include the loading code line in every model you create. Also you can easily push shared functionalities among models into the parent MY_Model class.

    Hope it helps!

提交回复
热议问题