php – Mysql插入编码问题

我试图在utf8_general_ci整理的单元格中插入Utf-8字符串

我的代码:

 <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'

我在数据库中看到的,作为插入行中的名称:

?AS

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

最佳答案 好的,谢谢大家的帮助,看起来我已经解决了这个问题:

 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的文章,这给了我一个提示)

点赞