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
| <?php
function litFic($fichier, $annee)
{
global $connexion;
$f = fopen($fichier, 'r');
$i = 0;
while (($ligne = fgetcsv($f, 4096, ',')) !== FALSE)
{
$nb = sizeof($ligne) - 6;
$j = 0;
while ($j < $nb)
{
$sql = 'insert into test (id, no_dep, annee, no_semaine, indice)
values(0, \'' . $ligne[2] . '\', \'' . $annee . '\', ' . $j . ', ' . $ligne[$j + 6] . ')';
mysql_query($sql, $connexion);
$j ++;
}
$i ++;
}
fclose($f);
}
//-----------------------------------------------------
//-----------------------------------------------------
//-----------------------------------------------------
//-- à remplacer par tes paramètres de connexion ----------
include ('SetPath.php');
$connexion = connexion();
$fichier = 'test.csv';
$annee = 2007;
litFic($fichier, $annee); |
Partager