Jump to content

utf8 don't work in sql database…


web_master

Recommended Posts

hi,

 

Ive got a problem.

 

Look the site www.tetszik.hu

 

1. I use in MySql "latin1_swedish_ci" collation and when I send the text in admin panel with form in dbase text is looks good.

2. Then I export table from dbase (with data), and when I put it back I have the "??" as You see.

 

3. If I use the "utf8_unicode" (or other utf-8) enconding in sql base the came the "??" in a moment whet I put a character via form in dbase. Not all but some chars, like Ő, Í, Á ”...

 

What can be a problem? - is the problem on server?

Link to comment
https://forums.phpfreaks.com/topic/92862-utf8-dont-work-in-sql-database%E2%80%A6/
Share on other sites

Make sure every character set setting in your database is utf8 (I'm using utf8_unicode_ci for all my database and table collations). Also, the charset in your HTML should be utf8, but I see you've got that right.

 

Now, when doing any database interaction, put these queries before your MySQL query:

 

<?php
mysql_query("SET NAMES 'utf8'", $connection);
mysql_query('SET CHARACTER SET utf8', $connection);
?>

 

This should solve it.

OK, I will made this changes.

 

Only problem is, that this was fork for a few weeks ago... and on this server Ive got a lots of a sites, and than I must make a changes on a thousand of files ... :(

 

 

but still I dont understand why if I put the characters via form will be good (readable), and after export from dbase, and put it back in dbase this char will change on "??"

If you have a lot of data in latin1 you should find some way to convert it to utf8.

The data should stay as is when exporting/importing from and to the same database. But if you import some non-unicode data into an unicode database, and vice versa, you'll likely have some corrupted data.

 

So, if you're dealing with different (written) languages on one server (or simply use 'unusual' characters), your only option is to use utf8.

this is a server problem I think because in ut8 collation I cannot even put a chars to stay a good char, because in moment willbe changed to a "??"

 

I take care about a collations in whole dbase to be everything a latin1_swedish or utf8_unicode... :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.