Php codeigniter中关于查询的错误
我对CodeIgniter是新手。请在这个查询中帮助我,我将获取用户\u typeid。这是我的模型查询代码,第12行有一个错误 严重性:错误 消息:调用未定义的函数get() 这是什么错误Php codeigniter中关于查询的错误,php,codeigniter,model,Php,Codeigniter,Model,我对CodeIgniter是新手。请在这个查询中帮助我,我将获取用户\u typeid。这是我的模型查询代码,第12行有一个错误 严重性:错误 消息:调用未定义的函数get() 这是什么错误 <?php class Login_model extends MY_Model { function validate($data) { $condition = "user_email =" . "'&q
<?php
class Login_model extends MY_Model {
function validate($data)
{
$condition = "user_email =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
$this->db->select('usertype_id');
$this->db->from('user');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db-get();
if($query->num_rows() == 1) {
return $query->row_array();
}
else {
return NULL;
}
}
}
?>
在get()
这就像你在做$This->db
减去get()
,而get
不是一个函数
应该是这样的:
$query = $this->db->get();
请尝试下面的代码
你也可以在下面这样的地方使用
function validate($data) {
// It is only going to select usertype_id
$this->db->select('usertype_id');
$this->db->from('user');
$this->db->where('user_email', $data['username']);
$this->db->where('user_password', $data['password']);
$this->db->limit(1);
$query = $this->db->get(); // missing >
// if you do not want to use == 1 you can use > 0
if ($query->num_rows() == 1) {
return $query->row_array();
} else {
return FALSE;
}
}
您在$data['username']附近收到了用户电子邮件,应该是用户用户名吗?没问题,先生,在我的表格中,我输入了用户名,但在我的数据库中,它的用户电子邮件您也可以使用$this->db->where('username',$data['username'])
和$this->db->where('password',$data['password'))
error很明显,您的get()有问题。
function validate($data) {
// It is only going to select usertype_id
$this->db->select('usertype_id');
$this->db->from('user');
$this->db->where('user_email', $data['username']);
$this->db->where('user_password', $data['password']);
$this->db->limit(1);
$query = $this->db->get(); // missing >
// if you do not want to use == 1 you can use > 0
if ($query->num_rows() == 1) {
return $query->row_array();
} else {
return FALSE;
}
}