460 |
delphine |
1 |
<?php
|
|
|
2 |
class FloreDao extends Bdd {
|
|
|
3 |
|
|
|
4 |
public function integrerFlore($flore, $nom_flore){
|
|
|
5 |
$flore = array_map(array($this, 'proteger'), $flore);
|
|
|
6 |
$requete = "INSERT INTO sophy_{$nom_flore} VALUES ";
|
|
|
7 |
$i = 0; $j = 1000; $info = '';
|
|
|
8 |
foreach ($flore as $num => $nom) {
|
|
|
9 |
if ($i < $j) {
|
|
|
10 |
$requete .= " ({$num}, {$nom}), ";
|
|
|
11 |
} else {
|
|
|
12 |
$requete = substr($requete,0,-2).";";
|
|
|
13 |
$resultat = $this->requeter($requete);
|
|
|
14 |
if ($resultat === false) {
|
|
|
15 |
$info .= $nom_flore.$j." n'est pas intégrée.\n";
|
|
|
16 |
} else {
|
|
|
17 |
$info .= $nom_flore.$j." est intégrée.\n";
|
|
|
18 |
}
|
|
|
19 |
$j += 1000;
|
|
|
20 |
$requete = "INSERT INTO sophy_{$nom_flore} VALUES ({$num}, {$nom}), ";
|
|
|
21 |
}
|
|
|
22 |
$i++;
|
|
|
23 |
}
|
|
|
24 |
$requete = substr($requete,0,-2).";";
|
|
|
25 |
$resultat = $this->requeter($requete);
|
|
|
26 |
if ($resultat === false) {
|
|
|
27 |
$info .= $nom_flore.$i." n'est pas intégrée.\n";
|
|
|
28 |
//echo $requete."\n";
|
|
|
29 |
} else {
|
|
|
30 |
$info .= $nom_flore.$i." est intégrée.\n";
|
|
|
31 |
}
|
|
|
32 |
return $info;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function chargerDonnees($fichier, $table) {
|
|
|
36 |
$requete = "LOAD DATA INFILE '$fichier' ".
|
|
|
37 |
"REPLACE INTO TABLE $table ".
|
|
|
38 |
"CHARACTER SET utf8 ".
|
|
|
39 |
"FIELDS
|
|
|
40 |
TERMINATED BY ','";
|
|
|
41 |
$this->requeter($requete);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public function ajouterColonnes($donnees, $table) {
|
|
|
45 |
$this->preparerTable($table, 'sb_num_nom_retenu');
|
|
|
46 |
$this->preparerTable($table, 'sb_num_tax');
|
|
|
47 |
$this->lancerRequeteModification($table, $donnees);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
private function preparerTable($table, $colonne) {
|
|
|
51 |
$requete = "SHOW COLUMNS FROM {$table} LIKE '{$colonne}' ";
|
|
|
52 |
$resultat = $this->recuperer($requete);
|
|
|
53 |
if ($resultat === false) {
|
|
|
54 |
$requete = "ALTER TABLE {$table} ".
|
|
|
55 |
"ADD {$colonne} INT(5) ";
|
|
|
56 |
$this->requeter($requete);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private function lancerRequeteModification($table, $flore) {
|
|
|
61 |
foreach ($flore as $num_nom => $info) {
|
|
|
62 |
$requete = "UPDATE {$table} ".
|
|
|
63 |
"SET sb_num_nom_retenu = {$info['num_nom_retenu']} ".
|
|
|
64 |
", sb_num_tax = {$info['num_tax']} ".
|
|
|
65 |
"WHERE sb_id_num_bdnff = $num_nom ";//echo $requete."\n";
|
|
|
66 |
$res = $this->requeter($requete);
|
|
|
67 |
if ($res === false) {
|
|
|
68 |
$this->traiterErreur("erreur d'insertion pour le tuple %s", array($id));
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
?>
|