mysql查询在mysql中执行但在mysqli和mysql中没有被弃用,所以我必须在codeigniter中使用mysqli的语法:
$sql = "SELECT admin_email
FROM `tbl_admin`
WHERE `admin_email` = '" . $username . "' and `admin_password` = '" . $password . "'";
$query = $this->db->query($sql);
答案 0 :(得分:1)
您可以使用Codeigniter Query Bulider
$this->db->select('admin_email');
$this->db->from('tbl_admin');
$this->db->where('admin_email', $username);
$this->db->where('admin_password', $password);
$query = $this->db->get();
答案 1 :(得分:1)
我希望它有效......
$this->db->select('*');
$this->db->from('tbl_admin');
$this->db->where('admin_email', $username);
$this->db->where('admin_password', $password);
$query = $this->db->get();
$result = $query->row();
return $result;
答案 2 :(得分:0)
尝试......
$this->db->select('admin_email');
$this->db->where(
array(
'admin_email' => $username,
'admin_password' => $password
));
$query = $this->db->get('tbl_admin');
$result = $query->row();
希望它能在你的作品中发挥作用......
答案 3 :(得分:0)
$this->db->where('admin_email',$email);
$this->db->where('admin_password',$password);
$qry = $this->db->get('tbl_admin');
if($qry->num_rows() > 0){
return true;
}else{
return false;
}
答案 4 :(得分:0)
仅当您在模型中设置查询然后在控制器中加载该模型时,该方法才能正常工作。直接从Controller设置查询似乎有此问题。
示例: 通过模型:示例“ Users.php”
class Users extends CI_Model {
public function __construct() {
parent::__construct();
}
function check_username($username) {
$query = $this->db->query("select * from `user_login` where `username`='$username'")
$query_result = $query->result_array;
if (!empty($query_result)) {
return $query_result;
}
return[];
}
}
在控制器中:示例“ Userauth.php”
class Userauth extends CI_Controller {
public function process_forgot(){
$CI =& get_instance();
$CI->load->model('Users'); //Model loaded here
$username = $this->input->post('username');
$check = $CI->Users->check_username($username);
echo '<pre>';
print_r($check);
echo '</pre>';
}
}
尝试一下。