Rev 880 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class FloreDao extends Bdd {
public function integrerFlore($flore, $nom_flore){
$flore = array_map(array($this, 'proteger'), $flore);
$requete = "INSERT INTO sophy_{$nom_flore} VALUES ";
$i = 0; $j = 1000; $info = '';
foreach ($flore as $num => $nom) {
if ($i < $j) {
$requete .= " ({$num}, {$nom}), ";
} else {
$requete = substr($requete,0,-2).";";
$resultat = $this->requeter($requete);
if ($resultat === false) {
$info .= $nom_flore.$j." n'est pas intégrée.\n";
} else {
$info .= $nom_flore.$j." est intégrée.\n";
}
$j += 1000;
$requete = "INSERT INTO sophy_{$nom_flore} VALUES ({$num}, {$nom}), ";
}
$i++;
}
$requete = substr($requete,0,-2).";";
$resultat = $this->requeter($requete);
if ($resultat === false) {
$info .= $nom_flore.$i." n'est pas intégrée.\n";
//echo $requete."\n";
} else {
$info .= $nom_flore.$i." est intégrée.\n";
}
return $info;
}
public function chargerDonnees($fichier, $table) {
$requete = "LOAD DATA INFILE '$fichier' ".
"REPLACE INTO TABLE $table ".
"CHARACTER SET utf8 ".
"FIELDS
TERMINATED BY ','";
$this->requeter($requete);
}
public function ajouterColonnes($donnees, $table) {
$this->preparerTable($table, 'sb_num_nom_retenu');
$this->preparerTable($table, 'sb_num_tax');
$this->lancerRequeteModification($table, $donnees);
}
private function preparerTable($table, $colonne) {
$requete = "SHOW COLUMNS FROM {$table} LIKE '{$colonne}' ";
$resultat = $this->recuperer($requete);
if ($resultat === false) {
$requete = "ALTER TABLE {$table} ".
"ADD {$colonne} INT(5) ";
$this->requeter($requete);
}
}
private function lancerRequeteModification($table, $flore) {
foreach ($flore as $num_nom => $info) {
$requete = "UPDATE {$table} ".
"SET sb_num_nom_retenu = {$info['num_nom_retenu']} ".
", sb_num_tax = {$info['num_tax']} ".
"WHERE sb_id_num_bdnff = $num_nom ";//echo $requete."\n";
$res = $this->requeter($requete);
if ($res === false) {
$this->traiterErreur("erreur d'insertion pour le tuple %s", array($id));
}
}
}
}
?>