2016-08-14 71 views
0

我的代碼笨數據庫中檢索都用大寫,小寫和大小寫混合

// My code: 

$this->db->select('*') 
->from('tbl_login') 
->where(['username'=>$this->input->post('username'),'password'=>$this->input->post('password')]); 
$result = $this->db->get()->result(); 

if($result) 
    var_dump($result) 
else 
    echo "not fount"; 

不要緊,什麼都我輸入「ADMIN1」或「ADMIN1」 &「密碼1」或「PASSWORD1」 它從表中檢索數據。 但我真正想要的是數據將被檢索時案件匹配正確。

誰能幫助??? ...

+0

您的數據庫列可能使用不區分大小寫的排序規則進行定義。將它們的整理更改爲區分大小寫,你應該沒問題。 – eggyal

+1

**警告**:不要編寫自己的用戶認證系統,因爲有許多方法可能導致錯誤。使用**純文本密碼**就是這樣的失敗之一。 [Codeigniter有很多包](http://stackoverflow.com/questions/33311725/codeigniter-3-x-authentication-library)已經工作。我強烈建議您找到適合您需求的產品,或者您已經足夠接近以適應您的需求。 – tadman

回答

0

試試這個

$query = $this->db->select("*")->from("tbl_login")->where("BINARY username= '".$this->input->post('username')."' and password = '".$this->input->post('password')."'"); 

    $result = $this->db->get()->result(); 

    if($result) 
     var_dump($result) 
    else 
     echo "not found"; 

注:在您查詢條件的地方基本上前使用BINARY

希望這會有所幫助!