我有从MySQL数据库提取数据的古怪的字符 [英] I got weird characters extracting data from MySQL db

查看:175
本文介绍了我有从MySQL数据库提取数据的古怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个MySQL数据库,编码为u​​tf8_unicode_ci,它像当前应用程序(用代码Igniter编写)一样运行。

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)

在开发一个新的PHP应用程序,当我尝试恢复数据,几个字符是不可读的 - 字符出现确定在数据库与phpMyAdmin,但是当我试图把它放在一个网页,它变得像ROLA 60

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".

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

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

问题出在哪里?我已将页面设置为 meta http-equiv =Content-Typecontent =text / html; charset = UTF-8,我试过mysql_set_charset没有。

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?

推荐答案

我注意到我的数据库驱动的应用程序的这个确切的问题,它花了我很长的时间来完成它!

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).

确保您的字符集在以下位置匹配:

Make sure your character sets match in the following places:


  1. HTML头部。

  2. 数据库归类本身 - 这可以在phpMyAdmin中设置
  3. 最常被忽视的字符集设置:php.ini文件的default_charset值(可以是通过PHP脚本或httpd.conf文件设置)。
  1. The HTML head section.
  2. The database collation itself - this can be set in phpMyAdmin when you create a new table, or alter the schema of an existing table.
  3. 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).

从您的帖子判断,看起来您的PHP配置可能设置为使用不同的default_charset。这意味着你的数据库将存储的字符精细,并将sendign的字符精细到你的脚本,但PHP脚本本身不知道该怎么做的字符,因此输出到浏览器的烦人的问号符号。

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.

尝试将php.ini值更改为相同的字符集,您可能会惊讶地看到字符显示很好!如果您无法访问php.ini,可以使用以下函数更改值:

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");

希望这有帮助。

这篇关于我有从MySQL数据库提取数据的古怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆