Php 如何在数据库中以UTF-8格式存储特殊字符

Php 如何在数据库中以UTF-8格式存储特殊字符,php,mysql,iis,utf-8,rich-text-editor,Php,Mysql,Iis,Utf 8,Rich Text Editor,我正试图在数据库中存储英镑。我还在集合中将此字段标记为utf8\u general\u ci。但它另存为�. 我还在元标记HTML文件中设置了UTF-8。这里少了什么 ---------编辑------ 我检查了一下,那个页面上有一个editorRich文本。如果我用这个编辑器保存数据,它会生成� 但是如果我使用文本框,它就可以正常工作。我不知道这个问题出了什么问题,也不知道如何调试这个问题 $query = "insert into field_master set fk_t_id = '".

我正试图在数据库中存储英镑。我还在集合中将此字段标记为utf8\u general\u ci。但它另存为�. 我还在元标记HTML文件中设置了UTF-8。这里少了什么

---------编辑------

我检查了一下,那个页面上有一个editorRich文本。如果我用这个编辑器保存数据,它会生成� 但是如果我使用文本框,它就可以正常工作。我不知道这个问题出了什么问题,也不知道如何调试这个问题

$query = "insert into field_master set fk_t_id = '".$_POST['t_id']."', fk_g_id = '".$_POST['g_id']."', fk_f_id = '".$_POST['f_id_'.$inc_i.'_'.$inc_j]."'".$str.", field_value = '".$field_value."', field_required = '".$required."', fk_section_id = '".$_POST['section_id_'.$inc_i]."', section_order = '".$_POST['section_order_'.$inc_i]."', field_order = '".$_POST['temp_order_'.$inc_i.'_'.$inc_j]."'";
$smt = $class->dbh->prepare($query);
$smt->execute();

当你真的搞砸了utf8的使用时,黑钻石上的问号。简单的答案是,用html别名latin1进一步搞乱它

“正确”的答案是在整个过程中使用utf8:

客户端中的字符编码为utf8。 连接是utf8-连接时通过执行集合名utf8或某些特定于语言的语法。见下文 列/表格上的字符集utf8。 HTML: 不同的事情会发生,这取决于你违反了哪一条

如果这些注释不足以解决您的问题,请选择col,HEXcol FROM。。。看看桌子上到底有什么。例如,您应该看到十六进制C2A3。如果您得到C382C2A3,则存在双重编码问题。如果你看不到,你就有莫吉贝克问题。如果以上都没有,那么这就是角色集问题的挑战所在

utf8\u general\u ci等排序规则用于排序;这与本讨论无关,仅显示字符集utf8或utf8mb4

mysqli接口:mysqli_set_字符集'utf8'


PDO接口:$db=new-PDO'dblib:host=host;dbname=db;字符集=UTF8',$user,$pwd

在表中插入列值“£”;在phpmyadminif query execute属性中尝试此手册,它意味着,您需要修复代码。。显示您的代码。。您必须使用ENT_QUOTE、'utf-8'或设置名称utf8等。@devpro:I已设置$stmt1=$class->dbh->prepareSET名称'utf8';手动运行插入查询可能重复的
The examples shown here assume use of the utf8 character set and utf8_general_ci collation.

Specify character settings per database. To create a database such that its tables will use a given default character set and collation for data storage, use a CREATE DATABASE statement like this:

CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;
Tables created in the database will use utf8 and utf8_general_ci by default for any character columns.

Applications that use the database should also configure their connection to the server each time they connect. This can be done by executing a SET NAMES 'utf8' statement after connecting. The statement can be used regardless of connection method: The mysql client, PHP scripts, and so forth.

In some cases, it may be possible to configure the connection to use the desired character set some other way. For example, for connections made using mysql, you can specify the --default-character-set=utf8 command-line option to achieve the same effect as SET NAMES 'utf8'.

If you change the default character set or collation for a database, stored routines that use the database defaults must be dropped and recreated so that they use the new defaults. (In a stored routine, variables with character data types use the database defaults if the character set or collation are not specified explicitly.

Specify character settings at server startup. To select a character set and collation at server startup, use the --character-set-server and --collation-server options. For example, to specify the options in an option file, include these lines:

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases.

I hope these information would be useful to you.