简体   繁体   中英

MySQL encoding issue with Turkish characters

I'm using WAMP server. I have my php.ini set to utf-8 and also I have header('Content-Type: text/xml; charset=utf-8'); in my php and @mysql_query("SET NAMES utf8"); in my connection file.

MySQL collation is set to utf8_turkish_ci and when I write my queries directly from phpMyAdmin the Turkish characters ç,ş,ö,ğ etc. show properly. But when I try to submit them from a php form, they turn into strange characters on the database, however when I write them again with php, they show properly.

My problem is, when I enter queries directly from phpMyAdmin, they don't show properly in PHP, and the vice versa, when I enter them from PHP they don't show properly in the database. How can I fix it?

Your data is being correctly stored in the database when you write the files using your script. The proof of this is that they come out correct when you echo back out the data. If you do not see the data correctly formatted in your phpmyadmin, it means that the page isn't properly set up to display utf-8.

The easiest way to check is to Ctrl+U to view the source code of your phpmyadmin and look for:

  < meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

It should also display:

MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation:    utf8_unicode_ci

On the very first page when you open phpMyAdmin. If you do not see both of these, then follow these steps to fix it:

A) Immediate solution I could think of is changing or forcing the browser's character encoding into utf-8. In Mozilla Firefox, it can be set via View -> Character Encoding -> Unicode (UTF-8)

or B) Another elegant solution might be changing the phpMyAdmin configurations so that it sends and sets proper charset in Content-Type header as Content-Type: text/html; charset=utf-8 . To do this, we have to edit the config.inc.php file found at phpMyAdmin's root directory:

$cfg['DefaultCharset'] = 'utf-8'; and 
$cfg['AllowAnywhereRecoding'] = true; 

These change of configurations should send proper headers. Anyhow, if the lang cookie is already set to some other charset, it won't reflect the changes. So, one may need to clear the cookies to see the changes.

Credit for above solutions: http://rajeshanbiah.blogspot.com/2004/12/storing-unicode-texts-in-mysql-with.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM