utf-8 chars conversion when store data

mathiand posted 5 years ago in Feature discussion
When I enter text in a field in the data tab and use national (swedish) chars, like å ä ö, theese are stored as iso-8859-1, even when the collation is set to utf-8.
Is it possible to convert the entered text into correct collation?

ansgar posted 5 years ago
Your table or column in that table has the wrong collation than. Please paste the CREATE TABLE query here so I can tell you what you need to do to fix that. HeidiSQL's connection to the server always runs in utf8 mode.
mathiand posted 5 years ago
`sida_id` int(10) NOT NULL AUTO_INCREMENT,
`code` varchar(50) COLLATE utf8_swedish_ci NOT NULL,
`titel` varchar(50) COLLATE utf8_swedish_ci NOT NULL,
`taborder` int(10) NOT NULL DEFAULT '0',
`enable` int(10) NOT NULL DEFAULT '1',
`updated` datetime NOT NULL,
PRIMARY KEY (`sida_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci;
mathiand posted 5 years ago
If I (in HeidiSQL) enter text, "åäö" (swedish chars) it is stored in DB exactly this way, and its wrong. It chould be in utf-8 (Ã¥ , ä , ö).

With PHP everything is ok.
ansgar posted 5 years ago
You should expect broken chars like å only when you're using the wrong charset. As said, HeidiSQL runs in utf8 mode, therfore utf8 chars are displayed the right way.

Your CREATE TABLE code looks perfect - everything's ok here, so you should not expect broken chars here.
ansgar posted 5 years ago
Ah, and åäö are surely displayable in utf8, probably not in latin1. So, if you have a php website which runs in latin1 you get broken chars. Not so when you run it in utf8 mode.
mathiand posted 5 years ago
My PHP site run in utf-8 and everything is ok, and everything is okay when I store text from php into db.

I _only_ taking about when I write text in fields inside HeidiSQL. I want some feature that "convert" written åäö into utf-8 and store it in db.

Is is possible?

ansgar posted 5 years ago
That's what I was trying to explain - your table and its columns are already utf8 "compatible", and so is HeidiSQL itself. You should never see broken chars like å or similar in that table. If you would see these, some client, PHP or whatever did that with a Latin1 based connection, and your data is broken!
ansgar posted 5 years ago
Does your PHP site fire some "SET NAMES utf8" before writing text into that table? It should definitely, otherwise your connection uses the servers default charset, which is latin1 on a default MySQL installation - see it via SHOW VARIABLES LIKE 'character_set_server'.
mathiand posted 5 years ago
Thank you!!

The SET NAMES make it works.

When I do SHOW VARIABLES the result is:

I think its right, but not working.

No OK, thank you again!!!

jfalch posted 5 years ago
the problem was probably not character_set_server but character_set_client, which is also changed by SET NAMES.
mathiand posted 5 years ago
character_set_client is sett to utf8 too.

Problem is solved, and I say thank you so much.

Please login to leave a reply, or register at first.