我已将SQL Server 2014与CodeIgniter连接。但是当我运行查询时,就会出现该错误。
这是给出错误的代码。
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');
}
}
错误是
致命错误:调用未定义方法CI_DB_sqlsrv_driver :: result() 第14行上的D:\ Xampp \ htdocs \ CI_Portal \ application \ models \ my_model.php
答案 0 :(得分:0)
尝试将$this->db->result();
更改为$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();
实际获得表结果之后,结果资源就存在了。
或者您可以将其用作:
$data = $this->db->get()->result();
答案 1 :(得分:0)
我尝试在application / config / database.php中进行配置更改
$active_group = "default";
$active_record = TRUE;
$query_builder = TRUE;
并尝试使用清除缓存并尝试。