drpsrvu85668 2013-04-10 12:49
浏览 139

UTF8立体派字符在MySQL数据库中无法识别

I have well known but quite difficult to sort out problem here. And yes I was searching on forum but those threads are old enough so I decided to create new post. So I built a website using WP and included html FORM in one page. When user fills the form (in his/her language) the values of the fields' go into MySQL database table reg_form.

Everything works, the values are saved, BUT some characters (specific in that language) are not recognized. I tried a lot of different methods to solve this, but nothing can help.

The strangest thing is that if you look at WordPress tables you can find those specific characters are recognizable but not in reg_form table which I created.

I was trying to solve this problem and finally I decided to approach in somehow ridiculous way. I created NEW database, new tables, installed new wordpress, created new form etc.

That‘s what I was doing:

I used this suggestion first: http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/

Yes, my files are saved using UTF8 encoding (without BOM). Yes, meta tags are ok. Yes, the FORM uses accept-charset='UTF-8'. Yes, all tables in database use UTF8. Yes, server, database and tables collation is the same “utf8_general_ci”.

Then I tried to insert in my code this:

$conn = mysql_connect($server, $username, $password);

mysql_set_charset("UTF8", $conn);

Then I tried this suggestion link here: akrabat.com/php/utf8-php-and-mysql/

Then I tried to set Apache's AddDefaultCharset in .htaccess file using this link here: httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset

BUT… still the problem remains. I can’t see those specific characters properly – only weird hieroglyphic.

  • 写回答

2条回答 默认 最新

  • douzi8112 2013-04-10 12:56
    关注

    The problem you face has to do with a little specific detail in database character encoding settings and Wordpress.

    While Wordpress has a general character encoding setting that normally takes care about database tables as well, it does not care about the default character encoding setting of the database those tables are in.

    So when your plugin/code adds a database table your own, you need to take care about the encoding settings as well - because by default they will be the database default you create the table in, which most likely is latin-1 which does not work well for your language.

    To set the default character set for the database (replace "wpdb" with your database name if it varies):

    ALTER DATABASE wpdb CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    To change the character set for your existing table *"reg_form"*:

    ALTER TABLE reg_form CONVERT TO CHARACTER SET charset_name;
    

    Note: Backup your database first.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度