我有两个文件:config.php 和 add.php 我想在数据库中插入英语和俄语数据。
config.php 的代码
<?php
header('Content-Type: text/html; charset=utf-8' );
$link = mysql_connect('asd','asd','asd') or die('Cannot connect to the DB');
mysql_select_db('asd',$link) or die('Cannot select the DB');
mysql_query("set character_set 'utf8'");
mysql_set_charset("utf8", $link);
echo mysql_client_encoding($link);
printf( "MySQL server version: %s\n", mysql_get_server_info());
?>
配置中最后两行的输出是:
utf8
MySQL server version: 5.1.72-rel14.10
从 add.php 页面我得到一个数组:
Array
(
[0] => Array
(
[message] => Registered
[detail] => Array
(
[id] => 54
[name] => Настройки
)
)
)
现在我尝试将其转换为 JSON
echo json_encode($posts,128);
但我得到的输出为
\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438
对于名称,数据库排序规则为 utf8_general_ci,数据库中的条目格式正确,但我无法以正确的格式获取数据。注意:请忽略SQL,稍后我会更改它。
最佳答案
你可以试试 :
echo json_encode($posts, JSON_UNESCAPED_UNICODE);
关于php - 在mysql数据库中插入和获取不同的语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28739925/