Editing UTF-8 data

[expired user #6197]'s profile image [expired user #6197] posted 12 years ago in Feature discussion Permalink
Hey!

I tried to edit a database I have in utf8_unicode_ci collation (and so are all of the tables and their columns), but the unicode characters I insert are not encoded in UTF-8 when sent to the server, and thus display incorrectly on a website later on. Is there a way to change the character set of HeidiSQL itself?

Unicode characters inserted as UTF-8 from other sources also display with some weird symbols when viewing with HeidiSQL.

Thanks in advance!
kalvaro's profile image kalvaro posted 12 years ago Permalink
HeidiSQL works fine with UTF-8. I use it all the time.

Are you sure your existing data is correctly stored? There's a simple test you can do: save the euro symbol (€) from your other source and run a query with the HEX() function, e.g.:

SELECT HEX(column_name) FROM table_name WHERE record_id=123


If you return this:

E282AC
kalvaro's profile image kalvaro posted 12 years ago Permalink
Typo: it should return
[expired user #6197]'s profile image [expired user #6197] posted 12 years ago Permalink
Thanks for the reply!

The one I inserted myself from HeidiSQL returned E282AC, but the one inserted via a query in a PHP file returned C3A2E2809AC2AC. The latter one works and displays correctly in browsers (site's charset is set to UTF8), but incorrectly in HeidiSQL (shown as "€" there).

Any idea what I might be doing wrong?
[expired user #6197]'s profile image [expired user #6197] posted 12 years ago Permalink
Typo: UTF-8 (not with the smiley)
kalvaro's profile image kalvaro posted 12 years ago Permalink
I'm afraid that your data is already corrupted. I've seen that situation several times: some PHP code is missing the "UTF-8" bit somewhere, typically in the connection settings. E.g. for PDO:

$conn = new PDO('mysql:host=localhost;dbname=database', 'user', 'pass', array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
//PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', <-- Missing
));


Your browser receives from the user and sends € to MySQL, but the same process is done when retrieving data so nobody notices because data looks good from within the app.
[expired user #6197]'s profile image [expired user #6197] posted 12 years ago Permalink
Ah, I wasn't aware that "SET NAMES utf8" was needed. Thank you, the data is now consistent!smile

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