mySQL和PHP编码

编程入门 行业动态 更新时间:2024-10-27 12:32:33
本文介绍了mySQL和PHP编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

HI,我有这个查询的问题

I have a problem with this query

SELECT * FROM table WHERE `name` LIKE '%tést%'

HMTL和SQL表都有utf-8编码,但遗憾的是没有$ code> mysql_set_charset('utf-8')而我不可以使用它。

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.

我'\\'尝试使用 iconv(UTF-8,ISO-8859-1,$ name),但查询只匹配 test 。

I've tried with iconv("UTF-8", "ISO-8859-1", $name) but the query matches only test.

我想匹配所有这些: test,tést,tèst,tëst因为它可以与 mysql_set_charset 一起使用)

I want to match all of these : test, tést, tèst, tëst (as it would work with mysql_set_charset )

编辑:

SET NAMES utf8 更为可能...数据库是使用utf8编码,不幸的是内容正在从$ code> mysql_set_charset 或 SET NAMES 。

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:

当我使用 SET NAMES utf8 它只匹配tést,它们看起来像<$当我使用 iconv(UTF-8,ISO-8859)时,c $ c> t?st

when I use SET NAMES utf8 it matches only tést and they look like tést

-1,$ name)它只匹配 test

when I use iconv("UTF-8", "ISO-8859-1", $name) it matches only test

推荐答案

在查询之前尝试:

mysql_query("SET NAMES 'utf8'", $conn);

* 编辑 *

*edits*

根据MySQL版本,您可能还需要使用:

Apprently depending on MySQL version you might also be required to use:

mysql_query("SET CHARACTER SET utf8", $conn);

最后要注意的是,数据库需要使用UTF-8字符集,以确保:

One final note, the database needs to be using the UTF-8 character set, to ensure this:

ALTER <database_name> DEFAULT CHARACTER SET utf8;

* 更多编辑 *

*More edits*

阅读完编辑后,我认为这是HTML / PHP编码的问题。在提交字符的页面上确保您正确设置标题:

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:

header('Content-Type: text/html; charset=UTF-8');

您还应该通过元标记设置:

You should also set this via meta tags:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

然后使用 mb_internal_encoding() 功能:

Then set the multibyte encoding with the mb_internal_encoding() function:

mb_internal_encoding("UTF-8");

默认情况下,PHP使用ISO-8859-1。

By default PHP uses ISO-8859-1.

更多推荐

mySQL和PHP编码

本文发布于:2023-11-22 03:06:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615736.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mySQL   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!