如何使用 LOAD DATA INFILE 命令在 MySQL 中输入特殊字符

How to Enter Special Character In MySQL using LOAD DATA INFILE Command

美好的一天,

我有一个逗号分隔值文件,我正在使用 Data Infile 命令将其插入到 MYSQL 数据库中..

但是我无法使用此命令在我的数据库中输入“Ñ”字符。

我认为数据文件命令不会像这样读取特殊字符。

谁能告诉我怎么做。

非常感谢您的帮助。

这些是我的代码。

<?php
 require 'config.php';

$sql1 = "TRUNCATE TABLE roster";
$result=$conn->prepare($sql1);
$result->execute();

$sql2 = "LOAD DATA INFILE 'NCR_ROSTER.csv' INTO TABLE roster FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n' 
IGNORE 1 LINES 
(family_id, enrollment_type, batch, family_status, person_id, first_name, 
middle_name, last_name, ext_name, grantee, relation, gender, ispregnant,
birthday, age, member_status, occupation, highest_educ_attained, 
attending_school, school_facility_id, school_facility_name, school_facility_address,
current_grade_level, for_educ_monitoring, reason_for_not_attending_school, attending_health_center, 
health_facility_id, health_facility_name, health_facility_address, for_health_monitoring,
reason_for_not_attending_health, region, province, municipality, barangay, purok, sitio)";
$result=$conn->prepare($sql2);
$result->execute();

echo "Roster data successfully imported to database!!";

 ?>

我找到了问题的答案..

我只需要将我的数据库整理类型更改为 UTF-8..

能够read/buffer个Unicode字符..

这就是我所做的..

ALTER table 'table_name' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

现在开始工作了..

谢谢大家..