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
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.

Link to comment
Share on other sites

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 "??"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.