[英]PHP, MySQL, characters not being displayed correctly.
I have a database that has the names of players (it's stats db for game), but when i fetch the player names with mysqli query i'm getting some wierd results. 我有一个拥有玩家名字的数据库(它是游戏的统计数据),但是当我用mysqli查询获取玩家名字时,我得到了一些奇怪的结果。
For example the characters "Α†Ω" are displayed as "? ?". 例如,字符“Α†Ω”显示为“? ?”。
What can i do to display these (and other) characters correctly? 如何正确显示这些(和其他)字符?
You have to set the connection charset to utf8. 您必须将连接字符集设置为utf8。
Execute the following function: http://php.net/manual/en/mysqli.set-charset.php 执行以下功能: http : //php.net/manual/en/mysqli.set-charset.php
Or execute the following query: 或者执行以下查询:
SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8
While fetching the result at the client side from database. 从数据库中获取客户端的结果时。 You have to specify about connection charset.
您必须指定有关连接字符集的信息。 So it is better to mention charset in the mysql config file.
所以最好在mysql配置文件中提到charset。 After successful connection, write the following code line:
连接成功后,写下以下代码行:
mysqli_set_charset($con,"utf8"); // Change character set to utf8
使用mysqli,您必须在建立连接后运行此代码:
mysqli_set_charset($conn, "utf8");
You need to set the charaset for the connection from php. 你需要从php设置连接的charaset。 Put the following code after connecting to the database.
连接到数据库后,请输入以下代码。
mysql_query("SET NAMES utf8");
That is if you are using mysql ext. 那就是你使用的是mysql ext。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.