2

I have a mysql Database. And It contains a list of users. The users can choose their own username/passwords. Some users have decided to use characters like these in their usernames:

 or 

The database throws an error; "Incorrect String Value". This is caused because the characters above do not conform to the UT8 format that is required by the mysql database.

How can I detect characters like these to prevent undesired entries on the database?

  • 1
    All Unicode characters can be represented with UTF-8. Therefore something else is going on. How is the column specified? – Richard Apr 22 '16 at 13:05
  • The collation is set to utf8_general_ci - type varchar(255) The mySql version is below 5.5.3 –  Apr 22 '16 at 13:09
  • 1
    maybe interesting? [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) It as mentioned in the **Linked** section on the right hand column on this page. – Ryan Vincent Apr 22 '16 at 13:16
  • So the only solution is to update to mysql 5.5.3? –  Apr 22 '16 at 13:18
  • Tried setting UTF-8 all the way through first? The issue may not be at the database. It may be elsewhere? imo, check all the settings in the complete path from client to database? That question has many useful suggests to do this. Test it on your development server first to ensure you save and retrieve diffferent UTF-8 character? – Ryan Vincent Apr 22 '16 at 13:22
  • I tried to manually insert the two characters into a field in the database. And I received the error. So if the client side code works, it still wont insert it. –  Apr 22 '16 at 13:26
  • Well, you can still store usernames in the database - just encode them as something that you can store and convert them back to the original string when you display them? Or forbid them in usernames? To identify them then limit the character set or try and save it and detect the error? – Ryan Vincent Apr 22 '16 at 13:33
  • How can I detect them then if I want to forbid them? –  Apr 23 '16 at 00:15
  • I would probably use on of the answers here to ensure that 3 byte characters or less are used in the username string? http://stackoverflow.com/questions/2384260/how-do-i-find-the-number-of-bytes-within-utf-8-string-with-php. – Ryan Vincent Apr 23 '16 at 10:35

0 Answers0