简体   繁体   English

选择查询以删除Mysql中的这些字符

[英]Select Query to Remove these characters in Mysql

SELECT * FROM mytablename WHERE sku = 'AZ-EFCQ-5' LIMIT 0 , 30 SELECT * FROM mytablename WHERE sku ='AZ-EFCQ-5'LIMIT 0,30

In MySQL table (description field) there are some weird characters in the database.There are almost 400+ records with all these characters out of 200,000 records it seems. 在MySQL表(描述字段)中,数据库中有一些奇怪的字符,似乎有200多个记录中有将近400多个记录。

Example: The database record for one of the field shows the following when I run the query 示例:运行查询时,该字段之一的数据库记录显示以下内容

Select * from mytablename where sku='az123'

Replacement for TOY TRAIN 746 N&W J   Replacement Light Bulb

But when I run the same query in PHP and print it, it shows 但是当我在PHP中运行相同的查询并打印时,它显示

Replacement For TOY TRAIN 746 N&W JÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Replacement Light Bulb

I tried using the following solution at 我尝试在使用以下解决方案

How can I find non-ASCII characters in MySQL? 如何在MySQL中找到非ASCII字符?

This doesn't work, doesn't show any weird characters in Mysql, check the MySQL screenshot below 这不起作用,在Mysql中不显示任何奇怪的字符,请查看下面的MySQL屏幕截图 在此处输入图片说明

As further analysis in the chat has shown that there really is something broken concerning charset handling between the MySQL DB connection and the PHP process running, we came up with the following "solution": 聊天中的进一步分析表明,关于MySQL DB连接和正在运行的PHP进程之间的字符集处理确实存在一些问题,我们提出了以下“解决方案”:

SELECT replace(description, char(160), ' ') as description 
FROM dumpdata WHERE AZ_Code = 'AZ-EFK9-6' 

The hidden chars are in fact   隐藏的字符实际上是  s which somehow got introduced by an import process. s是由导入过程引入的。 As they do not carry any information, but are only disturbing, it was ok to just remove them by replacing them when reading the column (see SQL statement above). 由于它们不携带任何信息,而只是打扰,因此可以通过在阅读列时替换它们来删除它们(请参见上面的SQL语句)。 This isn't really the proper solution for the root cause - it feels more like a workaround. 这并不是真正的根本原因解决方案-感觉更像是一种解决方法。 However, for the given purpose, it was considered to be sufficient. 但是,对于给定的目的,这被认为是足够的。

NB for other readers who might have a similar issue: The DB connection is being driven by mysqli in object-oriented style. 注意:对于其他可能有类似问题的读者,请注意:数据库连接由mysqli以面向对象的方式驱动。 We tried to 我们试图

$conn->set_charset('utf8')

and confirmed via conn->get_charset() that this also was successful. 并通过conn->get_charset()确认这也成功。 However, the problem with the wired chars still appeared. 但是,有线字符的问题仍然出现。 Moreover, we also tried an explicitly cast with 此外,我们还尝试使用

SELECT cast(description as char character set utf8) 
FROM dumpdata WHERE `AZ_Code` = 'AZ-EFK9-6'

but also this did not trigger a proper charset conversion. 但这也没有触发正确的字符集转换。

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

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