Posted 24 July 2012 - 1:05 PM
We learn that utf-8 supports a wide list of languages. There was so much information to digest, I could not recall if every action is required when building a universal/multilingual site. Are all of these set by default? Particularly the database character set.
My mySQL is already set as (actually copied this straight from phpMyAdmin) utf8_unicode_ci Unicode (multilingual), case-insensitive
Would I then have to establish a charset and collation for the database?
Are these actions needed each time, here is a list I gathered up while reading.
Added to inbetween the head tags
<meta http-equiv="content-type" content="text/html; charset=utf-8"> -> Page 416-417
Must be the first line before any HTML, must be a php script page
header('Content-Type: text/html; charset=UTF-8'); -> Page 452 (and more information in Chapter 14)
CREATE DATABASE forum2 CHARACTER SET utf8; -> Page 444
mysqli_set_charset($dbc, 'utf8'); or mysqli_query($dbc, 'SET NAMES utf8'); -> Page 450
Any one with some insight on this great appreciated with any comments.
Posted 24 July 2012 - 11:17 PM
1) MySQL DBs will not have their charset/collation set to UTF-8 by default. Whenever I create a new DB, I always manually set the collation to utf8_general_ci.
2) If the DB collation is set to utf8_general_ci, then all text fields in the tables in the DB should automatically default to the same collation. If this isn't the case, just manually override any fields that you need UTF-8 for.
3) In order for a PHP script to be able to handle UTF-8 data sent to it, you must either use the HTML <meta charset="UTF-8"> element or execute the header('Content-Type: text/html; charset=UTF-8') command. The alternative is to edit your php.ini file so that the default charset is UTF-8.
4) In order to get the DB connection to properly send UTF-8 data back and forth, you need to execute the mysqli_set_charset($dbc, 'utf8') command. Be careful, as the 'utf8' argument is case sensitive. I believe it's also possible to set the default charset in the php.ini file, but I'm not sure about that.
If you do those four things, then all of your non-English/multilingual scripts/DBs should work fine.
Edit: It was kinda vague in my original post, but I should differentiate between charset and collation. For a clear explanation, please see the following:
Posted 25 July 2012 - 12:17 PM
I had to read that great example twice per stackoverflow - but i finally go it.
I've made a number of Japanese DBs, and here's what I've observed:
3) In order for a PHP script to be able to handle UTF-8 data sent to it, you must either use the HTML <meta charset="UTF-8"> element or execute the header('Content-Type: text/html; charset=UTF-
Page 452 - 453, Or using both is fine I guess.
Either way, this satisfies my question.
Posted 25 July 2012 - 1:17 PM
How do we add Francais, Greek, Portuguese, an Japanese to the table? It's not taking them because they are in a different language. I copy pasted them off the web, don't know if that's the reason why.
I have taken these steps in my mysql client (shell).
(1) mysql > CHARSET UTF8;
(2) have altered all my tables to utf8 encoding
INSERT INTO languages (lang, lang_eng) VALUES
Posted 25 July 2012 - 8:15 PM
If it's the latter, what kind of code are you using for your PHP script?
Posted 25 July 2012 - 8:42 PM
mysql > INSERT INTO languages (lang, lang_eng) VALUES
But when I get to the first instance of a different encoding, it doesn't paste correctly.
Posted 25 July 2012 - 8:47 PM
It just refuses to take the different language encodings.
Posted 25 July 2012 - 10:03 PM
Although, more than likely, your table is not properly set up.
Could you please show the table structure?
Posted 26 July 2012 - 12:12 AM
I hope the tables help, I am trying to locate that the tables are in fact using UTF8, but couldn't find it. Thanks.
Posted 26 July 2012 - 12:45 AM
Posted 26 July 2012 - 1:28 AM
Glad you resolved the issue though.
Good luck with the rest of your project.