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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog