简体   繁体   English

如何更改列以支持unicode

[英]How do I alter column to support unicode

I have created a simple database table called players : 我创建了一个名为players的简单数据库表:

CREATE TABLE player (
    id              int(10)
                    NOT NULL
                    AUTO_INCREMENT
                    PRIMARY KEY,

    name            varchar(256)
                    NOT NULL
);

ALTER TABLE  players
    CHANGE name name
        varchar(256)
        CHARACTER SET utf8mb4
        COLLATE utf8mb4_unicode_ci;

I want to insert this entry into the database '𝔸𝕝𝕠𝕟𝕖' so I type 我想将此条目插入数据库'𝔸𝕝𝕠𝕟𝕖'所以我输入

INSERT INTO player (name) VALUES ("𝔸𝕝𝕠𝕟𝕖")

However, when inserted, the name value becomes '???????????' 但是,插入时,名称值变为'???????????' .

How can I fix this and keep my database table as efficient as possible.? 如何解决此问题并尽可能保持数据库表的有效性。

Most of the names are normal ASCII characters but sometimes I have these fancy unicode characters. 大多数名称都是普通的ASCII字符,但有时我会有这些奇特的unicode字符。

As discussed over the comments : you have correctly altered your table so the name column accepts utf8 characters. 正如评论中所讨论的:您已正确更改了表,因此name列接受utf8字符。

In this MySQL 5.7 DB Fiddle , string '𝔸𝕝𝕠𝕟𝕖' is properly inserted and displayed. 这个MySQL 5.7 DB Fiddle中 ,正确插入并显示字符串'𝔸𝕝𝕠𝕟𝕖'

It is very likely that the issue that you are having commes from your client, which is not properly passing data to the MySQL server. 很可能是您从客户端获得了commes的问题,该问题没有正确地将数据传递到MySQL服务器。

Since you are using PHP with the mysqli extension, you can set the default client character set for the connection by using the mysqli::set_charset function : 由于您使用带有mysqli扩展名的PHP,因此可以使用mysqli::set_charset函数为连接设置默认客户端字符集:

$conn->set_charset("utf8mb4");

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

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