简体   繁体   English

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

[英]Connecting to the database in a Created Library - 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: 基本上我正在创建一个在CodeIgniter中使用的库,我收到此错误:

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. Functions.php文件相应地位于application/libraries文件夹中。

Line number 11 consists of this: 第11行包括:

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

Not sure as to why the db is an undefined property? 不确定为什么db是一个未定义的属性?

It's probably because you need to get the CI instance first since not everything is loaded yet: 这可能是因为您需要首先获取CI实例,因为尚未加载所有内容:

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

See if that helps. 看看是否有帮助。 Also see the instructions here . 另请参阅此处的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM