mySQL 和 PHP 编码
您好,我对此查询有疑问,
SELECT * FROM table WHERE `name` LIKE '%tést%'
HMTL 和 SQL 表都有 utf-8 编码,但不幸的是没有 mysql_set_charset('utf-8')
并且我不< /strong> 能够使用它。
我尝试过使用 iconv("UTF-8", "ISO-8859-1", $name) 但查询仅匹配 test
。
我想匹配所有这些: test, tést, tèst, tëst
(因为它可以与 mysql_set_charset
一起使用)
编辑:
SET NAMES utf8
几乎是可能的......数据库是使用utf8编码,不幸的是内容是从网络填充的,没有mysql_set_charset
也没有SET NAMES< /代码>。
目前,如果使用这些函数,结果会很混乱。
version()
5.1.41-3ubuntu12.9
edit2:
当我使用 SET NAMES utf8
时,它仅匹配 < ,它们看起来像 tést
code>tést当我使用 iconv("UTF-8", "ISO-8859-1", $name)
时 它仅匹配 test
HI, I have a problem with this query
SELECT * FROM table WHERE `name` LIKE '%tést%'
the HMTL and the SQL table both have utf-8 encoding but unfortunately there is no mysql_set_charset('utf-8')
and I'm NOT able to use it.
I've tried with iconv("UTF-8", "ISO-8859-1", $name)
but the query matches only test
.
I want to match all of these : test, tést, tèst, tëst
(as it would work with mysql_set_charset
)
edit:
SET NAMES utf8
is nigher possible ... the database is with utf8 encoding, unfortunately the content is being filled from web without mysql_set_charset
nor SET NAMES
.
Currently if these functions are used the results are messed up.
version()
5.1.41-3ubuntu12.9
edit2:
when I use SET NAMES utf8
it matches only tést
and they look like tést
when I use iconv("UTF-8", "ISO-8859-1", $name)
it matches only test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在查询之前尝试:
编辑
显然,根据 MySQL 版本,您可能还需要使用:
最后一点,数据库需要使用 UTF-8 字符集,确保这一点:
更多编辑
阅读您的编辑后,我认为这是您的 HTML/PHP 编码的问题。在提交字符的页面上,确保正确设置标题:
您还应该通过元标记进行设置:
然后使用 [
mb_internal_encoding()
][1] 函数设置多字节编码:默认 PHP使用 ISO-8859-1。
[1]: https://www.php.net/mb_internal_encoding
Before the query try:
edits
Apprently depending on MySQL version you might also be required to use:
One final note, the database needs to be using the UTF-8 character set, to ensure this:
More edits
After reading your edits I think that this is a issue with your HTML/PHP encoding. On the page submitting the characters ensure that you set the headers properly:
You should also set this via meta tags:
Then set the multibyte encoding with the [
mb_internal_encoding()
][1] function:By default PHP uses ISO-8859-1.
[1]: https://www.php.net/mb_internal_encoding
我刚刚进行了一次快速测试,MySQL 的工作方式正如您所期望的那样。
也许这是你连接数据库的方式,你可以尝试执行 SET NAMES 'utf8';在执行查询之前看看是否有帮助!
另外,请注意 mysql_set_charset 应采用 utf8,不带破折号!请参阅PHP 示例来确定!
干杯!
I have just performed a quick test, and MySQL works as you expect it to work.
Perhaps it's the way you connect to the database, you could try executing SET NAMES 'utf8'; before performing the queries and see if that helps!
Also, please note that mysql_set_charset should take utf8, with no dash! See an example from PHP to be sure!
Cheers!
尝试使用所需的正则表达式进行 regexp,例如
SELECT * FROM table WHERE name REGEXP #REGULAR EXP HERE#
try regexp with the desired regular expression like
SELECT * FROM table WHERE name REGEXP #REGULAR EXP HERE#
您尝试过设置名称吗?
Have you tried SET NAMES?