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

时间:2016-08-11 06:52:13

标签: php mysql utf-8 load-data-infile

美好的一天,

我有一个逗号分隔值文件,我使用Data Infile命令在MYSQL数据库中插入它。

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

我认为Data Infile Command不会读取这样的特殊字符。

有人可以告诉我如何做到这一点。

非常感谢你的帮助。

这些是我的代码。

<?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!!";

 ?>

0 个答案:

没有答案