0

i want to check username if taken, but eloquent is running weird for me... In my database, only one user is registered, username is yigitabi

when i try to get user where username is yigitabi it returns the row but when i try to get user where username is yiğitabi it returns same row...

i have tried querylog and my two query logs are here...

array(1) { [0]=> array(3) { ["query"]=> string(42) "select * from `users` where `username` = ?" ["bindings"]=> array(1) { [0]=> string(9) "yiğitabi" } ["time"]=> float(0.24) } }

array(1) { [0]=> array(3) { ["query"]=> string(42) "select * from `users` where `username` = ?" ["bindings"]=> array(1) { [0]=> string(9) "yigitabi" } ["time"]=> float(0.24) } }

How can i fix this situation?

7
  • If your current database collation is not UTF 8, try setting it to utf_8_unicode_ci Commented Jun 6, 2015 at 16:48
  • @chanafdo all tables are utf_8_unicode_ci and i changed db to utf_8_unicode_ci but nothing changed Commented Jun 6, 2015 at 16:51
  • Sorry about my previous comment. Try setting it to utf_8_bin. Commented Jun 6, 2015 at 16:55
  • @chanafdo still same. Commented Jun 6, 2015 at 16:57
  • Did you change the collation of database to the above in Laravel config? If not try after changing it. Commented Jun 6, 2015 at 17:00

1 Answer 1

1

There is an excellent discussion of the issue at MySQL matching unicode characters with ascii version.

In order to get this to work as you expect, you need to change the collation from utf8_unicode_ci to utf8_bin. However, you need to keep in mind that there are three collation settings: one for the database, one for each table, and then one for each field.

Changing one of these collations does not affect the others. Changing the collation on the database does not affect the collation set on any existing table or field; it changes the default collation for future tables. Likewise, changing the collation on a table does not affect the collation set on any existing fields in that table; it changes the default collation for future fields.

So, to directly address your issue, you need to change the collation on the username field to be utf8_bin. It is up to you to determine what other fields, tables, or database for which you may want to change the collation.

Sign up to request clarification or add additional context in comments.

1 Comment

patricus thank you, i wasn't know field collation, i have solved my problem when i changed collation of field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.