2

I have a very strange behaviour that I'm experiencing. When I run insert into with an UTF8 Character (specifically the 'ő' or 'ű' hungarian characters) it inserts a ? instead of the character. However if I echo it out right before passing into the query it shows the right characters.

What I have done:

  • I have set every possible collation, charset in the mysql tables and databases to UTF8.
  • I have called mysql_query("SET NAMES 'UTF8'");
  • I have called mysql_query("SET CHARACTER SET UTF8");
  • I have set website encoding with: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

What works as intended:

  • PHPMyAdmin
  • Echoing Special Characters from tables

It's working on a localhost server. The non local server's default encoding is ISO-8859-1 which I can't change.

3
  • Check your HTTP header as well. Even if you have the meta tag set, most browsers default to the HTTP header. Commented Aug 28, 2013 at 22:19
  • 2
    possible duplicate of UTF-8 all the way through Commented Aug 28, 2013 at 22:21
  • Seems like solved with utf-8 header and iso-8859-1 metatag strangely. Commented Aug 28, 2013 at 23:06

1 Answer 1

1

if you

1 - set your html page's lang encoding to utf-8 which includes your forms
2 - only use your forms to enter input into your related MySQL db tables
3 - set all collations to utf8_unicode_ci in your MySQL (tables and rows collations)
4 - if you have premission you can also setyour MySQL DB collation as utf8_unicode_ci

then you won't see entities in your mySQL records also

This is my solution I use and have no trouble with my mother language which also has lots of unicode characters.

Below I introduce you my db connection php code & recommend (by using prepared statements; please check http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)

//mysql bağlantısı
global $db_baglanti;
$db_baglanti = new mysqli(vt_host, vt_user, vt_password, vt_name);
if ($db_baglanti->connect_errno) 
{
    echo "MySQL bağlantısı kurulamadı: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if (!$db_baglanti->set_charset("utf8")) 
{
    printf("utf8 karakter setinin yüklenmesinde problem oluştu: %s\n", $db_baglanti->error);
} 
else 
{
    $db_baglanti->set_charset("utf8");
}

I think main point for you is number 2 in list above.

Also If you already have some document, edit your document's meta tag for charset declaration and use notepad++ encoding>convert to UTF-8 without BOM, save your document, safely go on with your UTF-8 characters from now on. (this is a solution for possible HTML side issues related to BOM)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.