LLLLLLL Posted April 27, 2011 Share Posted April 27, 2011 I have a MySQL DB table and DB column with utf8_unicode_ci collation. I'm getting two columns out of the DB, one with the name of a language in English, the other a name of the language in the native tongue. The values in the database store/display properly from PHP MyAdmin. However, the "native-tongue" text does not display properly on the site. (See attached image.) I tried htmlentities( $str, ENT_COMPAT, 'UTF-8' ) for displaying, but that seems to make things worse (French, Portuguese, Spanish, and Turkish all display as empty; something I have not seen before). I thought that the htmlentities function should cure this, but since it does not, I am stumped. Any help is appreciated. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2011 Share Posted April 27, 2011 What character encoding are you using on the web page where you are trying to display the information? What does your whole 'view source' of the page show? Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1206921 Share on other sites More sharing options...
LLLLLLL Posted April 27, 2011 Author Share Posted April 27, 2011 My apologies, sloppy post. I do indeed have <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the header, if that's what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1206926 Share on other sites More sharing options...
LLLLLLL Posted May 3, 2011 Author Share Posted May 3, 2011 Hi, I'm still looking for an answer to this. Here is more information: I copied the text français into a database upgrade file (text file) That text got inserted into the DB as Français. (When I view the data in phpMyAdmin) The text must have saved that way in the text file, too (when did it change?) This text DOES now display as français So should I be happy that it displays correctly? Should I not care how phpMyAdmin displays it? Sigh, so complicated Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1209707 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Your issue is most likely the one described in this great blog post: http://omegadelta.net/2010/11/23/when-you-thought-the-db-was-utf-8-but-it-wasnt/ MySQL is not alone in having a default character set for the client library. You want this to be correct end to end, but if you don't explicitly tell mysql that you want the client switch to utf8, otherwise it will use whatever the default is, which is often latin1. This is such a common problem that they recently added mysql_set_charset and that page has notes on the previous methods of handling this. I'm guessing here that you have a mismatch and that your application probably does not set the client character set for your mysql connections. Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1209797 Share on other sites More sharing options...
LLLLLLL Posted May 3, 2011 Author Share Posted May 3, 2011 I understand what you're saying here, and I will take a look at making these changes. However, I am still unable to explain that third bullet point above, as it has nothing to do with the database. In short: 1) I copied français into a text file and saved it. 2) When I edited the text file again, it had the jibberish text. Wassup with that? I'm using cPanel to do these "saves", and its encoding is indeed utf-8 Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1209856 Share on other sites More sharing options...
LLLLLLL Posted May 3, 2011 Author Share Posted May 3, 2011 Per my last entry, I didn't actually have the right encoding set for the file. So that's why it didn't work. Per the overall topic, the solution was to add mysql_set_charset(), as you suggested. Bravo. My shopping cart just got better! Quote Link to comment https://forums.phpfreaks.com/topic/234863-internationalization-characters-dont-display-as-they-are-in-db/#findComment-1209884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.