Reputation: 1950
I have a MySQL database that has certain unconventional character stored in it such as é
, ▲
, █▓░✌
, ᄼᄽᄾ
etc.
When I query them from the DB and attempt to display them on the webpage they simply show up as a ?
even though I have the following metatag in place: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and the DB collation is set to utf8_general_ci
How can I display these characters properly? Do they need to be stored in a different way inside the DB?
note: the characters are readable inside the DB, but not when I display them on the page.
Adding this into my dbconnect file solved my problem.
/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
Upvotes: 0
Views: 242
Reputation: 4528
The easiest way to fix this issue is to call the query "SET NAMES utf8" before accessing your utf8 charecters from DB
Upvotes: 1