0

插入数据库时​​出现奇怪字符的问题,不知疲倦地试图找出问题,但我没有想法......

基本上,如果我像这样插入这些数据(这只是测试):

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

这将在数​​据库中结束(注意 A 字符):

“...行业年度最受欢迎的 派对,  http://www.unitingagainstlungcancer.org/getinvolved/strolling-supper-with-blues-news'>Joan's...”

我试图排列所有字符设置:

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    

这个问题可能是什么?

4

2 回答 2

1

您可能缺少的一件事是设置连接时。在那里,您还应该将编码设置为 utf8。

例子:

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

但是,不要使用 mysql 扩展,它已被弃用: http: //php.net/manual/en/function.mysql-set-charset.php

于 2013-11-12T19:03:59.917 回答
1

尝试将 mysql 连接也设置为 UTF-8:

mysql_query("SET NAMES 'utf8'");
于 2013-11-12T19:05:01.387 回答