1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
while (!feof($fichier))
{
$uneLigne = fgets($fichier);
if(mb_strlen(trim($uneLigne),'UTF-8'))
{
if($i>0) // test pour ne pas lire la premiere ligne
{
$tableauValeurs = array() ;
$tableauValeurs = explode(',', $uneLigne);
// insertion des donnees dans la table
$id++ ;
// on ajoute l'id au début du tableau de valeurs
$res = array_unshift($tableauValeurs, $id);
// on exécute la requêtes avec les valeurs du tableau (dans l'ordre)
$sqlZero = "INSERT INTO mouvement(id_movement,movement_date,last_modified_time,statut,service_type,sens,origin,via_origin,destination,via_destination,pop_name,platform_time,platform_actual_time,service_open,day_shift,poste,occupancy_start_time,occupancy_end_time,service,operator,commander,pilot,tug) VALUES ";
$sqlArray = array();
foreach ($tableauValeurs as $k => $v)
{
$tmp = array($v["id_movement"], $v["movement_date"], $v["last_modified_time"], $v["statut"], $v["service_type"], $v["sens"], $v["origin"], $v["via_origin"], $v["destination"], $v["via_destination"], $v["pop_name"], $v["platform_time"], $v["platform_actual_time"], $v["service_open"], $v["day_shift"], $v["poste"], $v["occupancy_start_time"], $v["occupancy_end_time"], $v["service"], $v["operator"], $v["commander"], $v["pilot"], $v["tug"]);
$sqlArray[] = "(" . implode(',', $tmp) . ")";
if ($k % 300 == 299)
{ // One query each 300 INSERT
$sql = $sqlZero . implode(',', $sqlArray);
$st = $db->prepare($sql);
$st->execute();
$sqlArray = array();
}
}
if (count($sqlArray))
{
// execute last beam
$sql = $sqlZero . implode(',', $sqlArray);
$st = $db->prepare($sql);
$st->execute();
}
}
else
{
$i++;
}
}
} |
Partager