2

I need the searching in the database more sensitive and recognize the difference between the upper and lower case like passwords.

Model

function checker(){
    $this->db->select('*');
    $this->db->from('gift_cards');
    
    $this->db->join('gift_partners', 'gift_partners.gp_id = gift_cards.gift_part_id');
    if(isset($_POST["redeem"])){
        $redeemvalue=$this->input->post("redeem");
        $this->db->where('gift_id',$redeemvalue);
    }else{
    $this->db->where('gift_code',$this->input->post('gift_code'));
    $this->db->where('gift_part_id',$this->input->post('partner'));
    }
    
    $data=$this->db->get();
    if ($data->num_rows() > 0) {
        
        foreach ($data->result_array() as $row) {
                $dt[] = $row;
                
            }
        return $dt;
    }else{
        
        return false;
    }
}

I need the gift code more sensitive, I used WHERE condition but in searching back the same result if I searched with upper or lower case.

$this->db->where('gift_code',$this->input->post('gift_code'));
Vickel
  • 7,879
  • 6
  • 35
  • 56

1 Answers1

0

MySQL is not case-sensitive while comparing characters but it can be made case-sensitive with use of key "BINARY".

$this->db->where('BINARY gift_code',$this->input->post('gift_code'));

The above code will not work. You need to use SQL to achive your required result.

function checker(){
    $rawSql = "SELECT * FROM gift_cards JOIN ON gift_partners.gp_id = gift_cards.gift_part_id";

    if(isset($_POST["redeem"])){
        $redeemvalue=$this->input->post("redeem");
    
        $rawSql.=" WHERE gift_id=?";    
        $query = $this->db->query($rawSql, [$redeemvalue]);
        
    }else{
        $redeemvalue=$this->input->post("redeem");
    
        // Case Sensitive Query
        $rawSql.=" WHERE BINARY gift_code=? AND gift_part_id=?";    
        $query = $this->db->query($rawSql, [
                                        $this->input->post('gift_code'),
                                        $this->input->post('partner'))
                                        ]);
    
    }
    
    if ($query->num_rows() > 0) {
        
        foreach ($query->result_array() as $row) {
                $dt[] = $row;
                
            }
        return $dt;
    }else{
        
        return false;
    }
}
mail2bapi
  • 1,547
  • 1
  • 12
  • 18