我正在尝试从CSV文件导入数据集。这可以正常工作,但空值不会插入为NULL。
有人试图告诉我使用load infile函数,但我真的不明白它可以帮助我在这一个这里是代码。
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = mysql_real_escape_string($_FILES[csv][tmp_name]);
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if($data[0]){
mysql_query("INSERT IGNORE INTO faculty(FCode,FName,MName,LName,Gender,image_name,BDate,Title,Service,EmpStat,CollegeID,DepartmentID,dateCreated) values('".mysql_real_escape_string($data[0])."','".mysql_real_escape_string($data[1])."','" . mysql_real_escape_string($data[2])."','" . mysql_real_escape_string($data[3])."','" . mysql_real_escape_string($data[4])."','" . mysql_real_escape_string($data[5])."','" . mysql_real_escape_string($data[6])."','" . mysql_real_escape_string($data[7])."','" . mysql_real_escape_string($data[8])."','" . mysql_real_escape_string($data[9])."','" . mysql_real_escape_string($data[10])."','" . mysql_real_escape_string($data[11])."','$currentDate')") or die ("error in sql syntax" .mysql_error());
}
} while ($data = fgetcsv($handle,1000,",","'"));