php – CodeIgniter – 调用非对象上的成员函数select()

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – CodeIgniter – 调用非对象上的成员函数select()脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我对CodeignITer很新.这是我的代码
class User_model extends CI_Model {

    function validate_user() {

        $this->db->select('*');
        $this->db->From('user');
        $this->db->where('username',$this->input->post('username'));
        $this->db->where('password',md5($this->input->post('password')));
        $validate_user = $this->db->get();

        if($validate_user->num_rows == 1) {
            return TRUE;
        }
    }
}

我在模型文件中收到这个错误

Call to a member function select() on a non-object

目前我使用CodeIgniter版本2.1.0.请帮帮我!

我认为你必须加载“数据库”库.第一种方法是将“数据库”包含在你的application / config / autoload.PHP文件
$autoload['libraries'] = array('database','session');

或在你的类构造函数中:

class User_model extends CI_Model { 

     public function __construct() 
     {
           parent::__construct(); 
           $this->load->database();
     }
}

您可以在这里获得更多信息:http://ellislab.com/codeigniter/user_guide/database/connecting.html

脚本宝典总结

以上是脚本宝典为你收集整理的php – CodeIgniter – 调用非对象上的成员函数select()全部内容,希望文章能够帮你解决php – CodeIgniter – 调用非对象上的成员函数select()所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。