UTF8立陶宛字符在MySQL数据库中无法识别

时间:2023-01-06 14:42:09

I have well known but quite difficult to sort out problem here. And yes I was searching on forum but those threads are old enough so I decided to create new post. So I built a website using WP and included html FORM in one page. When user fills the form (in his/her language) the values of the fields' go into MySQL database table reg_form.

我知道但很难在这里解决问题。是的,我在论坛上搜索,但这些线程已经足够老,所以我决定创建新的帖子。所以我使用WP构建了一个网站,并在一个页面中包含了html FORM。当用户填写表单(用他/她的语言)时,字段的值将进入MySQL数据库表reg_form。

Everything works, the values are saved, BUT some characters (specific in that language) are not recognized. I tried a lot of different methods to solve this, but nothing can help.

一切正常,值保存,但某些字符(特定于该语言)无法识别。我尝试了很多不同的方法来解决这个问题,但没有什么可以帮到你。

The strangest thing is that if you look at WordPress tables you can find those specific characters are recognizable but not in reg_form table which I created.

最奇怪的是,如果你查看WordPress表,你可以发现那些特定字符是可识别的,但不是我创建的reg_form表中。

I was trying to solve this problem and finally I decided to approach in somehow ridiculous way. I created NEW database, new tables, installed new wordpress, created new form etc.

我试图解决这个问题,最后我决定以某种荒谬的方式接近。我创建了新数据库,新表,安装了新的wordpress,创建了新表单等。

That‘s what I was doing:

这就是我在做的事情:

I used this suggestion first: http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/

我首先使用了这个建议:http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/

Yes, my files are saved using UTF8 encoding (without BOM). Yes, meta tags are ok. Yes, the FORM uses accept-charset='UTF-8'. Yes, all tables in database use UTF8. Yes, server, database and tables collation is the same “utf8_general_ci”.

是的,我的文件使用UTF8编码保存(没有BOM)。是的,元标记是可以的。是的,FORM使用accept-charset ='UTF-8'。是的,数据库中的所有表都使用UTF8。是的,服务器,数据库和表格排序是相同的“utf8_general_ci”。

Then I tried to insert in my code this:

然后我尝试在我的代码中插入:

$conn = mysql_connect($server, $username, $password);

mysql_set_charset("UTF8", $conn);

Then I tried this suggestion link here: akrabat.com/php/utf8-php-and-mysql/

然后我在这里尝试了这个建议链接:akrabat.com/php/utf8-php-and-mysql/

Then I tried to set Apache's AddDefaultCharset in .htaccess file using this link here: httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset

然后我尝试使用此链接在.htaccess文件中设置Apache的AddDefaultCharset:httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset

BUT… still the problem remains. I can’t see those specific characters properly – only weird hieroglyphic.

但是......问题仍然存在。我无法正确看到那些特定的角色 - 只有奇怪的象形文字。

2 个解决方案

#1


0  

The problem you face has to do with a little specific detail in database character encoding settings and Wordpress.

您遇到的问题与数据库字符编码设置和Wordpress中的一些具体细节有关。

While Wordpress has a general character encoding setting that normally takes care about database tables as well, it does not care about the default character encoding setting of the database those tables are in.

虽然Wordpress具有一般字符编码设置,通常也会关注数据库表,但它并不关心这些表所在的数据库的默认字符编码设置。

So when your plugin/code adds a database table your own, you need to take care about the encoding settings as well - because by default they will be the database default you create the table in, which most likely is latin-1 which does not work well for your language.

因此,当您的插件/代码添加自己的数据库表时,您还需要注意编码设置 - 因为默认情况下它们将是您创建表的数据库默认值,这很可能是latin-1,而不是适合您的语言。

To set the default character set for the database (replace "wpdb" with your database name if it varies):

设置数据库的默认字符集(如果数据库名称不同,请将“wpdb”替换为数据库名称):

ALTER DATABASE wpdb CHARACTER SET utf8 COLLATE utf8_general_ci;

To change the character set for your existing table *"reg_form"*:

要更改现有表格的字符集*“reg_form”*:

ALTER TABLE reg_form CONVERT TO CHARACTER SET charset_name;

Note: Backup your database first.

注意:首先备份数据库。

#2


0  

HOLLY SHIT!! FINALLY! : ))))))))

HOLLY SHIT !!最后! :))))))))

The problem was that I was using mysqli_ queries. Now I tried to change to mysql_ (notice the change!) queries and it worked!! Two weeks of haaaaard working and researches... Phew!

问题是我使用的是mysqli_查询。现在我尝试更改为mysql_(注意更改!)查询,它工作了!!两周的haaaaard工作和研究...... P!

Now who can explain me properly the reasons of this phenomena? : ))

现在谁能正确解释我这种现象的原因? :))

#1


0  

The problem you face has to do with a little specific detail in database character encoding settings and Wordpress.

您遇到的问题与数据库字符编码设置和Wordpress中的一些具体细节有关。

While Wordpress has a general character encoding setting that normally takes care about database tables as well, it does not care about the default character encoding setting of the database those tables are in.

虽然Wordpress具有一般字符编码设置,通常也会关注数据库表,但它并不关心这些表所在的数据库的默认字符编码设置。

So when your plugin/code adds a database table your own, you need to take care about the encoding settings as well - because by default they will be the database default you create the table in, which most likely is latin-1 which does not work well for your language.

因此,当您的插件/代码添加自己的数据库表时,您还需要注意编码设置 - 因为默认情况下它们将是您创建表的数据库默认值,这很可能是latin-1,而不是适合您的语言。

To set the default character set for the database (replace "wpdb" with your database name if it varies):

设置数据库的默认字符集(如果数据库名称不同,请将“wpdb”替换为数据库名称):

ALTER DATABASE wpdb CHARACTER SET utf8 COLLATE utf8_general_ci;

To change the character set for your existing table *"reg_form"*:

要更改现有表格的字符集*“reg_form”*:

ALTER TABLE reg_form CONVERT TO CHARACTER SET charset_name;

Note: Backup your database first.

注意:首先备份数据库。

#2


0  

HOLLY SHIT!! FINALLY! : ))))))))

HOLLY SHIT !!最后! :))))))))

The problem was that I was using mysqli_ queries. Now I tried to change to mysql_ (notice the change!) queries and it worked!! Two weeks of haaaaard working and researches... Phew!

问题是我使用的是mysqli_查询。现在我尝试更改为mysql_(注意更改!)查询,它工作了!!两周的haaaaard工作和研究...... P!

Now who can explain me properly the reasons of this phenomena? : ))

现在谁能正确解释我这种现象的原因? :))