sql - PHP UTF-8 Encoding MYSQL Inserts? -
i have strange behaviour i'm experiencing. when run insert utf8 character (specifically 'ő' or 'ű' hungarian characters) inserts ? instead of character. if echo out right before passing query shows right characters.
what have done:
- i have set every possible collation, charset in mysql tables , databases 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 intended:
- phpmyadmin
- echoing special characters tables
it's working on localhost server. non local server's default encoding iso-8859-1 can't change.
if you
1 - set html page's lang encoding utf-8
includes forms
2 - use forms enter input related mysql db tables
3 - set collations utf8_unicode_ci
in mysql (tables , rows collations)
4 - if have premission can setyour mysql db collation utf8_unicode_ci
then won't see entities in mysql records also
this solution use , have no trouble mother language has lots of unicode characters.
below introduce 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 number 2 in list above.
also if have document, edit document's meta tag charset declaration , use notepad++ encoding>convert utf-8 without bom
, save document, safely go on utf-8 characters on. (this solution possible html side issues related bom
)
Comments
Post a Comment