简体   繁体   English

数据库中的怪异字符

[英]weird characters in database

hi i need to store the weird character in my database but when i am trying to do so the weird character is replace with unknown character. 嗨,我需要将奇怪的字符存储在数据库中,但是当我尝试这样做时,奇怪的字符将替换为未知字符。 i am giving you one example when i am try to enter in Sönke Wortmann in database it is stored as Sönke Wortmann. 我想举一个例子,当我尝试在数据库中输入SönkeWortmann时,将其存储为SönkeWortmann。 i want to store above text as same as it was.please tell me how can i do so 我想像上面一样存储上面的文本。请告诉我我该怎么做

You should use Unicode tables as well as a Unicode connection to your database. 您应该使用Unicode表以及与数据库的Unicode连接。

Assuming you use MySQL: 假设您使用MySQL:

Set the default character set of your table to utf8 and make sure the connection to your database is also using this character set: 将表的默认字符集设置为utf8,并确保与数据库的连接也使用此字符集:

$conn = mysql_connect($server, $username, $password);
mysql_set_charset("UTF8", $conn);

See also: http://nl3.php.net/manual/en/function.mysql-set-charset.php 另请参见: http : //nl3.php.net/manual/zh/function.mysql-set-charset.php

Check the character set of your current connection with: 使用以下命令检查当前连接的字符集:

echo mysql_client_encoding($conn);

See also: http://nl3.php.net/manual/en/function.mysql-client-encoding.php 另请参见: http : //nl3.php.net/manual/en/function.mysql-client-encoding.php

When creating your tables do something like this: 创建表时,请执行以下操作:

create table tableName (
    // Your table definition
) default charset = UTF8

If you have done these things and add weird characters to your table, you will see it is displayed correct. 如果您已完成这些操作并在表中添加了奇怪的字符,您将看到它显示正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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