dongzhaobai5982 2013-11-12 18:59
浏览 36
已采纳

插入MySQL DB时出现字符问题

Having an issue with strange characters showing up when inserting into a database, have tried tirelessly to figure out the issue but I am out of ideas...

Basically if I insert this data like so (this is just testing):

  $valy = "…industry's favorite </em><strong><em>party of the year</em></strong><em>, </em><a href='http://www.unitingagainstlungcancer.org/getinvolved/strolling-supper-with-blues-news'><span class='s1'><em>Joan's…";
  $valy = mysql_real_escape_string($valy);

  $query = "INSERT INTO test_table (data) VALUES ('".$valy."')";
  mysql_query($query,$dbhandle);

this will end up in the database (notice the A characters):

"...industry's favorite party of the year, http://www.unitingagainstlungcancer.org/getinvolved/strolling-supper-with-blues-news'>Joan's..."

I have tried to line up all the character settings:

php default_charset = utf-8
mysql table & row charset = utf-8
Mysql instance variables:
character set client    utf8
(Global value)  latin1  
character set connection    utf8    
(Global value)  latin1  
character set database  latin1  
character set filesystem    binary  
character set results   utf8    
(Global value)  latin1  
character set server    latin1  
character set system    utf8    

What could this issue be?

  • 写回答

2条回答 默认 最新

  • dou5454954610 2013-11-12 19:03
    关注

    One thing you may be missing is when you setup the connection. There you should also set the encoding to utf8.

    Example:

    $link = mysql_connect('localhost', 'user', 'password');
    mysql_set_charset('utf8',$link);
    

    However, don't use the mysql extension, it's deprecated: http://php.net/manual/en/function.mysql-set-charset.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了