我这里有这段代码,它允许我将数据从 csv 文件导入数据库,现在它的作用是在插入之前截断表,我之前尝试删除截断表,但它不会通过数据。我的意思是如何在这里修改此代码?我只需要它来插入数据,而不需要清空当前表!
谢谢..
$deleterecords = "TRUNCATE TABLE imovo"; //empty the table of its current records
mysql_query($deleterecords);
//Upload File
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
echo "<h2>Displaying contents:</h2>";
readfile($_FILES['filename']['tmp_name']);
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$import="INSERT into imovo(date,time,location,rbpos_id,mobile_number) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
//view upload form
}else {
}