我有从MySQL数据库中提取数据的怪异字符(I got weird characters extracting data from MySQL db)

编程入门 行业动态 更新时间:2024-10-23 12:37:16
我有从MySQL数据库中提取数据的怪异字符(I got weird characters extracting data from MySQL db)

好吧,我得到了一个MySQL数据库,编码为u​​tf8_unicode_ci,它像当前应用程序一样运行(用代码点燃器编写)

现在,我正在开发一个新的PHP应用程序,当我尝试恢复数据时,有几个字符是不可读的 - 字符在php中使用phpMyAdmin显示正常,但是当我尝试将它放入网页时,它变成了“ ROLA 60“。

这些字符是西班牙文字母,例如ñ,á,Ó...或ascii代码,如€,Ø...

问题在哪里? 我将页面设置为meta http-equiv =“Content-Type”content =“text / html; charset = UTF-8” ,我尝试了mysql_set_charset()函数,但仍然没有任何结果。

有这种问题的经验?

Well, I got a MySQL db, encoded as utf8_unicode_ci, and it runs like a charm with the current application (written in Code Igniter)

Now, I'm developing a new PHP app, and when I try to recover the data, several characters are unreadable - chars appears ok in the DB with phpMyAdmin, but when I try to put it up in a webpage, it became like "ROLA �60".

These characters are spanish letters, such as ñ, á, Ó... or ascii codes like €, Ø...

Where's the problem? I've set the page as meta http-equiv="Content-Type" content="text/html; charset=UTF-8", I've tried the mysql_set_charset() function, and still nothing.

Any experience with this kind of problems?

最满意答案

我在我的数据库驱动的应用程序中注意到了这个确切的问题,并且花了很长时间去解决它!

问题的发生是因为应用程序中至少有三个地方需要定义字符集,而且它们必须全都是相同的字符集(并且该字符集必须能够处理正在处理的字符)。

问号符号及其变化发生在浏览器不理解其传递的字符时。

确保你的字符集在以下地方匹配:

HTML头部分。 数据库整理本身 - 这可以在创建新表时在phpMyAdmin中设置,或者改变现有表的模式。 最容易被忽视的字符集设置 :php.ini文件的“default_charset”值(可以通过PHP脚本或httpd.conf文件设置)。

从你的帖子来看,它看起来像你的PHP配置可能被设置为使用不同的default_charset。 这意味着你的数据库将会存储好字符,并且会将字符很好地发送给你的脚本,但是PHP脚本本身不会知道如何处理这个字符,并且因此输出到浏览器作为烦人的问号符号。

尝试将php.ini值更改为相同的字符集,并且您可能会惊讶于看到字符显示正常! 如果您无权访问php.ini,则可以使用以下函数更改该值:

ini_set("default_charset", "UTF-8");

希望这可以帮助。

I have noticed this exact problem in my database driven applications, and it took me a long time to work it out!

The problem occurs because there are at least three places in your application that need their character sets defining, and they must all be the same character set (and that character set must be able to handle the characters you are handling).

The question mark symbol and it's variations occurs when the browser doesn't understand what character it is being passed.

Make sure your character sets match in the following places:

The HTML head section. The database collation itself - this can be set in phpMyAdmin when you create a new table, or alter the schema of an existing table. The most overlooked character set setting: The php.ini file's "default_charset" value (can be set via PHP script or the httpd.conf file).

Judging from your post, it looks like your PHP configuration might be set to be using a different default_charset. This means that your database will be storing the characters fine, and will be sendign the characters fine to your script, but the PHP script itself will not know what to do with the character, and thus outputs to the browser as the annoying question mark symbol.

Try changing the php.ini value to the same charset, and you may be surprised to see the characters displaying fine! If you don't have access to php.ini, you can change the value with the following function:

ini_set("default_charset", "UTF-8");

Hope this helps.

更多推荐

本文发布于:2023-07-08 20:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我有   数据库中   怪异   字符   数据

发布评论

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

>www.elefans.com

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