升级到 CodeIgniter 2.1,模型中多个数据库的使用现已损坏
我最近升级到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的函数
deauthorize_user
中未定义$machformsdb
。您应该调用$this->machformsdb
。另外:在您的构造函数中,
$this
已经是CI_Model
的实例,因此您不需要获取 CodeIgniter 单例实例。你可以这样写:$machformsdb
is not defined in your functiondeauthorize_user
. You should call$this->machformsdb
.In addition: in your constructor,
$this
is already an instance ofCI_Model
so you don't need to get the CodeIgniter singleton instance. You could just write: