[英]Character set in MySQL; Can't insert special characters, why?
I can't insert special characters. 我不能插入特殊字符。 Whenever I try to, all characters BEFORE the special character gets inserted, but after the special character nothing is inserted into the field.
每当我尝试插入时,都会插入特殊字符之前的所有字符,但是在特殊字符之后,则不会插入任何字符。
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname,$conn);
mysql_set_charset('utf-8', $conn);
mysql_query("SET NAMES 'utf8'") or die(mysql_error());
mysql_query("SET CHARACTER SET 'utf8'") or die(mysql_error());
I have set the table to utf-8 collation, and all fields as well... 我已将表格设置为utf-8归类,以及所有字段...
Any thoughts? 有什么想法吗?
Thanks 谢谢
Have you set the necessary UTF-8 parameters in your PHP config? 您是否已在PHP配置中设置了必要的UTF-8参数? I used to begin my PHP files with that:
我以前从那开始我的PHP文件:
ini_set("mbstring.internal_encoding","UTF-8");
ini_set("mbstring.func_overload",7);
I had same issue for saving special characters in mysql database so i changed Collation to utf8mb4_unicode_ci, it made the sql query run and complete data was inserted into database. 我在将特殊字符保存在mysql数据库中时遇到了同样的问题,因此我将Collation更改为utf8mb4_unicode_ci,它使sql查询运行并将完整的数据插入到数据库中。 But special characters not supported with UTF-8 are replaced by '?'.
但是UTF-8不支持的特殊字符被替换为'?'。 But I found it better till permanent fix atleast full data is inserted into database.
但是我发现,直到将永久修复至少完整数据插入数据库之前,它会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.