| 12
 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
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 
 |  
<?php
mysql_connect("localhost", "root", "root");
mysql_select_db("alcatel");
 
/*PrÈparation de la requÍte qui vide la table*/
/*pas forcÈment nÈcessaire, peut Ítre commentÈ*/
$sql = 'TRUNCATE TABLE enregistrement';
 
/*on exÈcute la requÍte*/
$result = mysql_query($sql);
/*on dÈfinit le fichier .csv*/
 
$fichier = "./semaine13.csv";
 
/*On ouvre le fichier  importer en lecture seulement*/
if (file_exists($fichier)) {
$fp = fopen("$fichier", "r");
}
else {
/*le fichier n'existe pas*/
echo "Fichier introuvable !<br />Importation stoppÈe.";
exit();
}
 
while (!feof($fp)) {
/*Tant qu'on n'atteint pas la fin du fichier on lit une ligne*/
$ligne = fgets($fp,4096);
/*On rÈcupËre les champs sÈparÈs par , dans liste*/
$liste = explode( ";",$ligne);
/*On assigne les variables*/
$variable1 = $liste[0];
$variable2 = $liste[1];
$variable3 = $liste[2];
$variable4 = $liste[3];
$variable5 = $liste[4];
$variable6 = $liste[5];
$variable7 = $liste[6];
$variable8 = $liste[7];
$variable9 = $liste[8];
$variable10 = $liste[9];
$variable11 = $liste[10];
$variable12 = $liste[11];
$variable13 = $liste[12];
$variable14 = $liste[13];
$variable15 = $liste[14];
$variable16 = $liste[15];
$variable17 = $liste[16];
/*Ajouter un nouvel enregistrement dans la table*/
$sql = "INSERT INTO enregistrement VALUES('$variable1','$variable2','$variable3','$variable4','$variable5','$variable6','$variable7','$variable8','$variable9','$variable10','$variable11','$variable12','$variable13','$variable14','$variable15','$variable16','$variable17')";
$result= mysql_query($sql);
 
if(mysql_error()) {
/*Erreur dans la base de donnees, s˚rement la table qu'il faut crÈer*/
print "Erreur dans la base de donnÈes : ".mysql_error();
print "<br />Importation stoppÈe.";
exit();
}
else {
/*Tout va bien*/
print "$variable1|$variable2|$variable3|$variable4|$variable5|$variable6|$variable7|$variable8|$variable9|$variable10|$variable11|$variable12|$variable13|$variable14|$variable15|$variable16|$variable17<br />";
/*Fermeture du fichier*/
fclose($fp);
 
echo '<br /><b>TABLE A JOUR ...</b><br />';
 
/*PrÈparation de la requÍte d'optimisation*/
$sql = 'OPTIMIZE TABLE enregistrement';
/*on exÈcute la requÍte*/
$result = mysql_query($sql);
 
echo '<br /><b>TABLE OPTiMiSEE ...</b><br />';
 
/*THE END*/
echo '<br /><b>O.K ! ALL DONE.</b><br />';
 
}
 
else {
echo'<br /><b>UPDATE FAiLURE !</b><br />';
}
?> | 
Partager