doubingqi5829 2018-10-25 04:55
浏览 110
已采纳

PHP Codeigniter调用未定义的方法CI_DB_sqlsrv_driver :: result()

I have Connected SQL Server 2014 with CodeIgniter. but when I run a query it gives that error.

This is the code which gives an error.

 function index()
  {
    $this->form_validation->set_rules('username', 'Username','required');
    $this->form_validation->set_rules('password', 'Password','required');
    if($this->form_validation->run() == TRUE)
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $this->db->select('*');
        $this->db->from('student');
        $this->db->where(array('student_id'=>$username,'password'=>$password));
        $query = $this->db->get();
        $data = $this->db->result();
        if($data)
        {
          echo "<pre> ";
          print_r($data);
        }
    }
  $this->login('login');
  }
}

The Error is

Fatal error: Call to undefined method CI_DB_sqlsrv_driver::result() in D:\Xampp\htdocs\CI_Portal\application\models\my_model.php on line 14

  • 写回答

1条回答 默认 最新

  • douba6361 2018-10-25 07:55
    关注

    Try be changing $this->db->result(); as $query->result();

    $this->db->select('*');
    $this->db->from('student');
    $this->db->where(array('student_id' => $username, 'password' => $password));
    $query = $this->db->get();
    $data = $query->result();
    

    The result resource is there after you actually get the table results.

    Or you can use it as:

    $data = $this->db->get()->result();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!
    • ¥15 matlab+波形匹配算法