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 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 83
| <?php
$bdd = "base";
$host= "localhost";
$user= "root";
$pass= "";
@mysql_connect($host,$user,$pass) or die("Impossible de se connecter à la base de données");
@mysql_select_db($bdd);
function lit_xml($fichier,$item,$champs) {
if($chaine = @implode("",@file($fichier))) {
$tmp = preg_split("/<\/?".$item.">/",$chaine);
for($i=1;$i<sizeof($tmp)-1;$i+=2)
foreach($champs as $champ) {
$tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
$tmp3[$i-1][] = @$tmp2[1];
}
}
return $tmp3;
}
$adresse="flux.xml";
$dstName="nouveau.xml";
function uncompress($adresse, $dstName) {
$string = implode("", gzfile($adresse));
$fp1 = fopen($dstName, "w");
fwrite($fp1, $string, strlen($string));
fclose($fp1);
}
uncompress("$adresse","$dstName");
$fn=fopen($dstName,"r");
$xml = lit_xml("nouveau.xml","product",array("TDProductId","name","description","imageUrl","productUrl","price","currency","id","name","merchantName","name","value","name","value","name","value","name","value"));
foreach($xml as $row) {
$id_produit_marchand = $row[0];
$url_fiche_produit = $row[4];
$url_image = $row[3];
$prix_ttc = $row[5];
$description = $row[2];
$nom_du_marchand = $row[9];
$categorie = $row[7];
$disponibilite = $row[11];
$frais_port_ttc = $row[13];
$marque = $row[15];
$reference_constructeur = $row[17];
$query= "INSERT INTO table values('" . addslashes($nom_du_marchand) . "','" . addslashes($id_produit_marchand) . "', '" . addslashes($categorie) . "', '" . addslashes($libelle) . "', '" . addslashes($url_fiche_produit) . "', '" . addslashes($url_image) . "', '" . addslashes($prix_ttc) . "', '" . addslashes($ecotaxe_ttc) . "', '" . addslashes($frais_port_ttc) . "', '" . addslashes($disponibilite) . "', '" . addslashes($ean) . "', '" . addslashes($reference_constructeur) . "', '" . addslashes($description) . "', '" . addslashes($marque) . "', '" . addslashes($garantie) . "', '" . addslashes(date("Y-m-d H:i:s")) . "', '" . addslashes($date_time_modification) . "', '" . addslashes("1") . "')";
$result= MYSQL_QUERY($query);
}
if(mysql_error())
{
print "Erreur dans la base de données : ".mysql_error();
print "<br>Importation stoppée.";
exit();
}
MYSQL_CLOSE();
?> |