Ich muss eine große CSV nach MySQL hochladen, wenn ich Pausen hochladen muss, muss ich an der Stelle beginnen, wo ich aufgehört habe, keine doppelten Einträge. Wenn Prozess bricht dann sollte es neu starten, von wo ich automatisch beendet (dh: wenn das Hochladen Pause nach 123 Einträge dann sollte es von 124 auf den nächsten Lauf wieder aufnehmen)Wie lade ich eine große CSV-Datei mit PHP ohne doppelte Einträge in MySQL hoch?
CSV-Dateiformat:
latitude longitude
6.5486 72.456
4.2186 74.466
5.5486 82.956
ich nur brauchen ein Eintrag mit dem gleichen Längen- und Breitengrad, momentan benutze ich den unten stehenden Code (funktioniert), aber ich weiß nicht, wie ich vom Bruchpunkt anfangen soll, wenn ich Pausen einlege.
<?php
error_reporting(0);
require("connection.php");//connect to the database
if ($_FILES[csv][size] > 0){
//get the csv file
$file = $_FILES[csv][tmp_name];
echo $fname = $_FILES['csv']['name'];
echo $ftype = end(explode('.', strtolower($fname)));
if($ftype=="csv"){
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
$latitude=$data[0];
$longitude=$data[1];
$location1=$data[2];
$location2=$data[3];
$location3=$data[4];
$sql = "SELECT * FROM latitude_longitude WHERE latitude ='$latitude' AND longitude='$longitude' ";
$result=mysql_query($sql);
if(mysql_num_rows($result) > 0){
mysql_query("UPDATE latitude_longitude SET latitude = '$latitude',longitude = '$longitude',location1='$location1', location2='$location2',location3='$location3',status=status+1 WHERE latitude = '$latitude' AND longitude = '$longitude'");
}
else{
mysql_query("INSERT INTO latitude_longitude (latitude, longitude, location1, location2, location3, status, date) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."',
'1',
CURRENT_TIMESTAMP
)
");
}
}
} while ($data = fgetcsv($handle,1000,",","'"));
//redirect
header('Location:GeoLocation.php?success=1'); die;
}else{
header('Location:GeoLocation.php?success=2'); die;
}
}
?>
danke für die Hilfe im Voraus.
Erstellen Sie einen eindeutigen Schlüssel auf Länge, Breite Sie können etwas wie unten verwenden – Priyanshu