3

I've just discovered an issue where city names that contain accent marks, e.g. La Cañada, Peñasco, etc., won't save to my database. Looking through the answers to another SO question, What is the best collation to use for MySQL with PHP?, I've tried changing both my database and the varchar's collation type from latin1_swedish_ci to utf8_general_ci which still refused the character. I also tried utf8_unicode_ci with a similar result.

I've verified that the save works if I strip out the accent mark on the client side, but ideally I'd like to keep it in there, since that is the real name of the city (according to google maps apis anyway).

What collation types do you use to support ñ?

Additional info: Using MySQL, phpMyAdmin, and CakePHP with an Android app as the client


Thanks for the suggestions so far. I guess this is turning into a CakePHP question now... I noticed that by default utf8 is not enabled, so I enabled it in my app/config/database.php file. I FTPed the file back to the server and tried it again still without any luck. Do I need to redeploy the application to kick off those db config changes, or is there another area of my application I should check? First time CakePHP user here.

Community
  • 1
  • 1
Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
  • 1
    Most utf8 collations shouldn't have any problems with this character. How does your `INSERT`-statement look like? Does your connector to the mysql database use utf8? – Bjoern Nov 10 '12 at 10:38
  • latin1 charset supports ñ. I don't think the issue is in the charset. – Al_ Nov 10 '12 at 10:54
  • I remember a had a similar issue with the `£` symbol and although I wasn't using cake, the application had the inflector of cake in it. Are you filtering with `Cake/Utility/Inflector.php`? – Al_ Nov 10 '12 at 11:16
  • I see the Cake/Utility/Inflector.php file but I honestly couldn't say if I'm actively using it. Does Cake use the filter by default? – Kyle Clegg Nov 10 '12 at 11:26

1 Answers1

3

Collation is merely the order in which characters are sorted, which is a necessary step in performing comparisons. It has nothing to do with how data is stored (except insofar as a given collation is specific to some encoding).

Character encoding is the mapping of characters to their binary representation for storage, which determines the supported character set.

However, just because a database/table/column are using a particular character encoding is not the end of the story. You must also consider the encoding used within your application and on its interfaces with other components (such as MySQL).

Whilst it's aimed at PHP, UTF-8 all the way through pretty much covers all of the things you need to consider.

Community
  • 1
  • 1
eggyal
  • 122,705
  • 18
  • 212
  • 237
  • You must be right, it has to be related to character encoding in my web application. I've tried a couple things with cakephp and have updated my question with additional detail. – Kyle Clegg Nov 10 '12 at 11:06