gpt4 book ai didi

mysql - 无法在mysql中显示波兰语字符

转载 作者:行者123 更新时间:2023-11-30 23:19:12 25 4
gpt4 key购买 nike

这可能看起来像重复的,但我已经搜索了几个小时,但针对类似问题的建议修复都没有奏效:

我在 xls 文件中有已转换为 CSV 的文本。它包含波兰字符。我已经确认我确实保存为 UTF8 编码。我无权访问此服务器上的 PHPMyAdmin,因此我将此 UTF8 编码的 CSV 文件上传到服务器。

然后我使用 UTF8 编码的 PHP 文件加载数据库:

        mb_language('uni');
mb_internal_encoding('UTF-8');
setlocale(LC_ALL, "pl_PL.UTF-8");
require_once('config.php');
mysql_set_charset('utf8');
$f=fopen('questions-final2.csv','r');
$questions=array();
while (($data = fgetcsv($f, 1000, ",")) !== FALSE) {
//$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
print_r($data);
$questions[]=$data;
//mysql_query('INSERT INTO questions(question_id,text,answer_time,difficulty,mode) VALUES '.implode(',',$inserts));
//echo $data;
}

//exit();
// import of questions
$prev_index=0;
foreach($questions as $index=>$question){
if($index>0)
if($question[0]==$questions[$prev_index][0])
unset($questions[$index]);
else
$prev_index=$index;
}

mysql_query('SET CHARACTER SET utf8');
mysql_query('SET NAME utf8');

$res=mysql_query('SELECT * FROM questions');

$inserts=array();
foreach($questions as $question)
$inserts[]='("'.$question[5].'","'.addslashes($question[1]).'","'.$question[7].'","'.$question[0].'","'.$question[4].'")';

mysql_query('INSERT IGNORE INTO questions(question_id,text,answer_time,difficulty,mode) VALUES '.implode(',',$inserts));

var_dump(mysql_error());

fclose($f);

现在,这是数据库的内容:

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

我无法让 latin1 部分消失。我的 my.conf 看起来像这样:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
default-character-set = utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

我正在使用 putty 并确认我也将其设置为 utf8 编码,这是输出:

mysql> select text from questions limit 1;
+-------------------------------------------+
| text |
+-------------------------------------------+
| ?wi?to Unii Europejskiej obchodzone jest: |
+-------------------------------------------+
1 row in set (0.00 sec)

这是应有的原文:

Święto Unii Europejskiej obchodzone jest:

我也试过了:

alter table questions modify column text TEXT character set utf8 collate utf8_unicode_ci;

alter table questions convert to character set utf8 collate utf8_unicode_ci;

导入数据前后都没有用。我在这里缺少什么?

最佳答案

mysql_query('SET NAME utf8');

这个查询应该触发一个错误:

SQL Error (1193): Unknown system variable 'NAME'

...但是您没有看到它,因为您没有测试 mysql_query() 是否成功。 The correct variable is NAMES .

关于mysql - 无法在mysql中显示波兰语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16306697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com