土耳其语字符的MySQL编码问题 [英] MySQL encoding issue with Turkish characters

查看:129
本文介绍了土耳其语字符的MySQL编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WAMP服务器。我将php.ini设置为utf-8,并且还有
header('Content-Type:text / xml; charset = utf-8'); 在我的php和
@mysql_query( SET NAMES utf8); 在我的连接文件中。



MySQL归类设置为utf8_turkish_ci,当我直接从phpMyAdmin编写查询时,土耳其语ç,ş,ö,ğ等显示正确。但是,当我尝试从php表单提交它们时,它们在数据库中变成了奇怪的字符,但是当我再次用php编写它们时,它们却显示正确。



我的问题是,当我直接从phpMyAdmin输入查询时,它们在PHP中无法正确显示,反之亦然,当我从PHP输入查询时,它们在数据库中无法正确显示。我该如何解决?

解决方案

使用脚本编写文件时,您的数据已正确存储在数据库中。这证明当您回显数据时它们正确显示。如果您没有在phpmyadmin中看到正确格式化的数据,则表明该页面未正确设置为显示utf-8。



最简单的检查方法是Ctrl + U来查看phpmyadmin的源代码并寻找:

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

还应显示:

  MySQL字符集:UTF-8 Unicode(utf8)
MySQL连接排序规则:utf8_unicode_ci

在打开phpMyAdmin的第一页。如果您没有同时看到这两种情况,请按照以下步骤进行修复: -8。在Mozilla Firefox中,可以通过查看->字符编码-> Unicode(UTF-8)



或B进行设置。另一个优雅的解决方案可能是更改phpMyAdmin配置,这样它发送并在Content-Type标头中将适当的字符集设置为Content-Type:text / html; charset = utf-8。为此,我们必须编辑在phpMyAdmin根目录中找到的config.inc.php文件:

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

这些配置更改应发送适当的标头。无论如何,如果lang cookie已经设置为其他字符集,则不会反映所做的更改。因此,可能需要清除cookie才能看到更改。



上述解决方案的信用: http://rajeshanbiah.blogspot.com/2004/12/storing-unicode-texts-in-mysql-with.html


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

这篇关于土耳其语字符的MySQL编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆