Wednesday, 29 August 2018

Why sql query does not return data if I search for an exact string?

I have mysql table called with column name gift_code which type is varchar(20) and now it's contain GREATDAY string data.

Now why I a run following sql query it's return 0. I don't understand why it's happening ?!
The string can contain Uppercase or Lowercase characters. I want to search exact match
$checkPromo     = mysqli_query($conn, "SELECT * FROM gift_card WHERE gift_code = 'GREATDAY'   ");
echo $numPromo   = mysqli_num_rows($checkPromo);

I used BINARY keyword but not working :(

COLLATE utf8_general_cs is what matters. When the column's collate is set to this, the case-sensitive will work. if your column collate is utf8_general_ci this will ignore the case sensitiveness while querying.

0 comments:

Post a Comment