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

dongmen9517
dongmen9517 试试这个$query->result()
接近 2 年之前 回复
doushang7209
doushang7209 尝试更改$data=$this->db->result();to$data=$query->result();.
接近 2 年之前 回复

1个回答

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();
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问