dongxie3681 2011-12-01 01:48
浏览 30
已采纳

连接到创建的库中的数据库 - CodeIgniter

I have a little issue right now and its bugging me, hopefully one of you guys will be able to help me out.

Basically I'm creating a library to use in CodeIgniter and I'm getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Functions::$db

Filename: libraries/Functions.php

Line Number: 11

The Database library is already on autoload aswell as my functions library:

$autoload['libraries'] = array('database','session','encrypt','functions');

The Functions.php file is located in the application/libraries folder accordingly.

Line number 11 consists of this:

$this->db->where('username', $data);

Not sure as to why the db is an undefined property?

  • 写回答

1条回答 默认 最新

  • du0173 2011-12-01 01:51
    关注

    It's probably because you need to get the CI instance first since not everything is loaded yet:

    $ci =& get_instance();
    $ci->db->where('username', $data);
    

    See if that helps. Also see the instructions here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?