升级到 CodeIgniter 2.1,模型中多个数据库的使用现已损坏

发布于 2024-12-27 18:02:54 字数 854 浏览 1 评论 0原文

我最近升级到 CodeIgniter 2.1。下面的模型代码 (machforms_model.php) 在我之前的 CI 安装中正常工作。我还确认我的database.php 文件与之前的安装相同,因此数据库配置不应该是我的问题的根源。我现在看到的错误消息是: Fatal error: Call to a member function query() on a non-object in models/machforms_model.php on line 24,其中第 24 行是我的第一次查询尝试。

machforms_model:php
class machforms_model extends CI_Model 
{

    public function __construct() {
        parent::__construct();
        $CI =& get_instance();
        $CI->machformsdb = $this->load->database('machforms', TRUE);
        $this->machformsdb = $CI->machformsdb; 
    }


        function deauthorize_user($user_guid) {
        $sql = 'delete from ap_sessions where user_guid=?';
        $sql_result = $machformsdb->query($sql,array($user_guid));   // LINE 24     
    }
}

我不确定为什么会收到过载错误。如果其他外部文件/配置信息可能是罪魁祸首,请告知,我将相应地发布。

I recently upgraded to CodeIgniter 2.1. The below model code (machforms_model.php) was properly working in my previous CI install. I have also confirmed that my database.php file is identical to the previous install, so db configuration should not be the source of my problem. The error message I see now is: Fatal error: Call to a member function query() on a non-object in models/machforms_model.php on line 24, where line 24 is my first query attempt.

machforms_model:php
class machforms_model extends CI_Model 
{

    public function __construct() {
        parent::__construct();
        $CI =& get_instance();
        $CI->machformsdb = $this->load->database('machforms', TRUE);
        $this->machformsdb = $CI->machformsdb; 
    }


        function deauthorize_user($user_guid) {
        $sql = 'delete from ap_sessions where user_guid=?';
        $sql_result = $machformsdb->query($sql,array($user_guid));   // LINE 24     
    }
}

I am uncertain why I receive the overload error. If other external file/config information may be the culprit, please advise and I will post accordingly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-01-03 18:02:54

您的函数 deauthorize_user 中未定义 $machformsdb。您应该调用$this->machformsdb

另外:在您的构造函数中,$this 已经是 CI_Model 的实例,因此您不需要获取 CodeIgniter 单例实例。你可以这样写:

public function __construct() {
  parent::__construct();  
  $this->machformsdb = $this->load->database('machforms', TRUE);
}

$machformsdb is not defined in your function deauthorize_user. You should call $this->machformsdb.

In addition: in your constructor, $this is already an instance of CI_Model so you don't need to get the CodeIgniter singleton instance. You could just write:

public function __construct() {
  parent::__construct();  
  $this->machformsdb = $this->load->database('machforms', TRUE);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文