简体   繁体   English

PHP htmlentities无法正常工作? 输出是?

[英]PHP htmlentities not working? output is?

I am trying to store some data in my MySQL database. 我正在尝试在MySQL数据库中存储一些数据。 When I try to input special characters and even foreign characters like ø or звяф, I want them to be stored as html entities (like ő) 当我尝试输入特殊字符甚至是ø或звяф等外来字符时,我希望将它们存储为html实体(例如ő)

I thought it's supersimple, just use htmlentities(), but when I store data, I am getting nothing but ???? 我以为它很简单,只使用htmlentities(),但是当我存储数据时,我什么也没得到? in the database. 在数据库中。

Any ideas? 有任何想法吗?

Here is the code I use right now: 这是我现在使用的代码:

$sqlOrder="INSERT INTO data (
        bad, cname, lor
    )
    VALUES (
        '".htmlentities($b->getBad(), ENT_COMPAT, 'UTF-8')."', '".htmlentities($b->getCName(), ENT_COMPAT, 'UTF-8')."', '".htmlentities($b->getLor(), ENT_COMPAT, 'UTF-8')."'
    )";

As said, the result in the database is ????????? 如前所述,数据库中的结果为????????? for any special characters such as кршуцкыя or æåø. 用于任何特殊字符,例如кршуцкыя或æåø。

What is the data collation of your database? 数据库的数据整理是什么? By default, most MySQL installs set latin1_swedish_ci instead of utf8_general_ci for newly created databases. 默认情况下,大多数MySQL为新创建的数据库安装set latin1_swedish_ci而不是utf8_general_ci

Change the collation of the database & try again. 更改数据库的排序规则,然后重试。

ALTER DATABASE [name of your database] CHARACTER SET utf8;

If this is a specific table, the collation can be changed as so: 如果这是一个特定的表,则排序规则可以更改为:

ALTER TABLE [name of your table] CONVERT TO CHARACTER SET utf8;

And if it is a specific column in a table: 如果它是表中的特定列:

ALTER TABLE [name of your table] MODIFY [name of your column] [other settings] CHARACTER SET utf8 COLLATE utf8_general_ci;

Or perhaps you could export the current database, create a new database with this command & reimport the data: 或者,您可以导出当前数据库,使用此命令创建新数据库并重新导入数据:

CREATE DATABASE [name of your database] CHARACTER SET utf8 COLLATE utf8_general_ci;

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

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