2013-07-04 47 views
4

我试图插入UTF-8字符串的细胞与utf8_general_ci整理Mysql的插入编码问题

我的代码:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
... 

print mb_detect_encoding($name); 
$query = "INSERT INTO items SET name='$name', type='$type'"; 
print $query; 
mysql_set_charset('utf8'); // also doesn't help 
$result0 = mysql_query("SET CHARACTER SET utf8") or die(mysql_error()); // I've added this line, but it doesn't solve the issue 
$result01 = mysql_query('SET NAMES utf8') or die("set character ".mysql_error()); // still nothing 
$result = mysql_query($query) or die(mysql_error()); 

我在HTML输出中看到什么:

UTF-8 INSERT INTO waypoints SET name='ČAS', type='ts' 

我在数据库中看到的插入行为name

?AS 

现在我的字符串是utf-8,我的表和单元格是utf-8 ..为什么编码错了?

+0

你如何“看到它在数据库中”?也许这只是你工具的编码问题。 – Sirko

+0

['mysql_set_charset()'](http://www.php.net/manual/en/function.mysql-set-charset.php)怎么样? – BlitZ

+0

phpmyadmin ..无论如何,我试过选择和打印,它是stil?AS –

回答

2

玉家伙,感谢大家的帮助下,它看起来像我已经解决了这个问题与:

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $link); 

创造的文章,这给了连接

(尤其是@Bartdude之后我暗示)