Why is unicode not working in my MySQL table?
I have a MySQL DB table where I store addresses, including Norwegain addresses.
CREATE TABLE IF NOT EXISTS `addresses` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`street1开发者_高级运维` varchar(50) COLLATE utf8_danish_ci NOT NULL,
`street2` varchar(50) COLLATE utf8_danish_ci DEFAULT 'NULL',
`zipcode` varchar(10) COLLATE NOT NULL,
`city` varchar(30) COLLATE utf8_danish_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `index_store` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;
Now, this table was fine untill I screwed up and accidentaly set all cities = 'test'. Luckilly I had another table called helper_zipcode
. This table contains alle zipcodes and cities for Norway.
So I updated addresses
table with data from helper_zipcode
.
Unfortunately in the front end, cities like Bodø
now shows like Bod�
.
æ ø å
are now shown as � � �
(but they look fine in the DB).
I'm using HTML 5, so my header looks like this:
<!DOCTYPE HTML>
<head>
<meta charset = "utf-8" />
(...)
This is not the first time I struggle with unicode.
What is the seceret for storing unicode characters (from Europe) in DB and display the same way when retrieved from DB?
from mysql docs:
Posted by lorenz pressler on May 2 2006 12:46pm [Delete] [Edit]
if you get data via php from your mysql-db (everything utf-8) but still get '?' for some special characters in your browser (
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
), try this:after
mysql_connect()
, andmysql_select_db()
add this lines:mysql_query("SET NAMES utf8");
worked for me. i tried first with the
utf8_encode
, but this only worked for äüöéè... and so on, but not for kyrillic and other chars.
Is your problem storing the data in mysql or from retrieving the stored data using php?
Before query (1-st time) you must need add mysql_query("SET NAMES UTF8");.
What happens if you change your browser encoding from auto-detect to UTF-8 or Unicode ?
What I'm trying to determine if its the Database or the Web-browser that's wrong.
Alternatively. if you have a Database tool for your MySQL database, does that show the right or wrong characters ?
精彩评论