尝试使用“LOAD DATA INFILE”从 CSV(10k 记录)填充数据库表,但目前它什么也不做。
没有错误,没有数据输入,我不知道它有什么问题,所以任何帮助表示赞赏!
My code (-CSS and DBconnect):
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded
successfully." . "</h1>";
}
$temp_file = $_FILES['filename']['tmp_name'];
$origin_file = $_FILES['filename']['name'];
$target_file = 'uploads/'.$origin_file;
move_uploaded_file($temp_file, $target_file);
$file_name = $target_file;
$query = <<<eof
LOAD DATA LOCAL INFILE '$file_name'
INTO TABLE importing
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(text,number)
IGNORE 1 LINES
eof;
mysql_query($query);
print "Import done";
mysql_close();
//view upload form
}else {
print "Upload new csv by browsing to file and clicking on Upload<br />\n";
print "<form enctype='multipart/form-data' action='upload.php' method='post'>";
print "File name to import:<br />\n";
print "<input size='50' type='file' name='filename'><br />\n";
print "<input type='submit' name='submit' value='Upload'></form>";