插入数据库后,Unicode字符成为问号 [英] Unicode characters become question marks after inserting into the database

查看:84
本文介绍了插入数据库后,Unicode字符成为问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将一些用Unicode编写的文本插入数据库时​​,它们成为问号.数据库编码设置为UTF-8.还有什么可能是不正确的?当我签入phpMyAdmin时,仅插入了问号!

When I insert some text written in Unicode into database, they become question marks. Database encoding is set to UTF-8. What else may be incorrect? When I check in phpMyAdmin there are question marks inserted only!

这是我用于连接数据库的代码:

This is the code I use for connecting to database:

define ("DB_HOST", "localhost"); // Set database host
define ("DB_USER", "root"); // Set database user
define ("DB_PASS","password"); // Set database password
define ("DB_NAME","name"); // Set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

mysql_set_charset('utf8',$link);
mysql_query("SET CHARACTER SET utf8");

推荐答案

您插入的文本是否也以UTF-8编码?还是您的PHP文件不是UTF-8?您是否已将MySQL客户端连接设置为UTF-8?

Is the text you inserted encoded in UTF-8 too? Or is your PHP files not UTF-8? Have you set the MySQL Client connection to UTF-8?

如果不是,那可能是问题的原因.

If not, then that is probably the cause of the problem.

这篇关于插入数据库后,Unicode字符成为问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆