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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| <?php
$bdd = "csv";
$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);
$YourFile= "1665.csv";
$handle = fopen($YourFile, 'r');
while (!feof($handle))
{
for($i=0;$i<filesize("$YourFile");$i++)
{
$data[$i]=fgets($handle,4096);
$liste = explode( ";",$data[$i]);
$l0=$liste[0];
$l7=$liste[7];
$l1= $liste[1];
$l3= $liste[3];
$l6= $liste[6];
$l5= $liste[5];
$l8= $liste[8];
$l15= $liste[15];
$l9= $liste[9];
$l12= $liste[12];
$l11= $liste[11];
$l10= $liste[10];
$l4= $liste[4];
$l16= $liste[16];
$l17= $liste[17];
$l18= $liste[18];
$l19= $liste[19];
$l14= $liste[14];
$md=date("Y-m-d H:i:s");
$a= "select 'id_produit_marchand' from 'marchand'";
$sql= MYSQL_QUERY($a);
$nom_du_marchand =$l14;
$id_produit_marchand =$l0;
$categorie = $l1;
$libelle = $l3;
$url_fiche_produit = $l6;
$url_image = $l5;
$prix_ttc = $l7;
$ecotaxe_ttc = $l8;
$frais_port_ttc = $l15;
$disponibilite = $l9;
$ean = $l12;
$reference_constructeur = $l11;
$description = $l10;
$marque = $l4;
$garantie = $l16;
$date_time_creation = $liste[17];
$date_time_modification = $liste[18];
/***************************************test sur tous les champs pour la mise à jour*******************************************/
//NOM MARCHAND
$up1= "UPDATE marchand SET nom_du_marchand='" . $l14 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND nom_du_marchand <> '" . $l14."'";
$r1=MYSQL_QUERY($up1);
//CATHEGIRIE
$up3= "UPDATE marchand SET categorie='" . $l1 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND categorie <> '" . $l1."'";
$r2=MYSQL_QUERY($up3);
//LIBELLE
$up4= "UPDATE marchand SET libelle='" . $l3 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND libelle <> '" . $l3."'";
$r3=MYSQL_QUERY($up4);
//URL FICHE PRODUIT
/*if($url_fiche_produit!=$resultss);//$sqle)
{
$up5= "UPDATE marchand SET url_fiche_produit='" . $l6 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND url_fiche_produit <> '" . $l6."'";
$r4=MYSQL_QUERY($up5);
} */
//URL IMAGE
$up6= "UPDATE marchand SET url_image='" . $l5 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND url_image <> '" . $l5."'";
$r5=MYSQL_QUERY($up6);
//PRIX
$up7= "UPDATE marchand SET prix_ttc='" . $l7 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND prix_ttc <> '" . $l7."'";
$r6=MYSQL_QUERY($up7);
//ECOTAXE_TTC
$up8= "UPDATE marchand SET ecotaxe_ttc='" . $l8 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND ecotaxe_ttc <> '" . $l8."'";
$r7=MYSQL_QUERY($up8);
//FRAIS PORT
$up9= "UPDATE marchand SET frais_port_ttc='" . $l15 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND frais_port_ttc <> '" . $l15."'";
$r8=MYSQL_QUERY($up9);
//DISPONIBILITE
$up10= "UPDATE marchand SET disponibilite='" . $l9 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND disponibilite <> '" . $l9."'";
$r9=MYSQL_QUERY($up10);
//EAN
$up11= "UPDATE marchand SET ean='" . $l12 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND ean <> '" . $l12."'";
$r10=MYSQL_QUERY($up11);
//REFERENCE CONSTRUCTEUR
$up12= "UPDATE marchand SET reference_constructeur='" . $l11 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND reference_constructeur <> '" . $l11."'";
$r11=MYSQL_QUERY($up12);
//DESCRIPTION
$up13= "UPDATE marchand SET description='" . $l10 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND description <> '" . $l10."'";
$r12=MYSQL_QUERY($up13);
//MARQUE
$up14= "UPDATE marchand SET marque='" . $l4 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND marque <> '" . $l4."'";
$r13=MYSQL_QUERY($up14);
//GARANTIE
$up15= "UPDATE marchand SET garantie='" . $l16 . "', date_time_modification='" . $md . "', actif_non_actif=1 WHERE id_produit_marchand='" . $l0 . "' AND garantie <> '" . $l16."'";
$r14=MYSQL_QUERY($up15);
/***************************************test pour l'insertion*******************************************************************/
if(($id_produit_marchand)!=($sql))
{
$query = "INSERT INTO `marchand` (`nom_du_marchand`, `id_produit_marchand`, `categorie`, `libelle`, `url_fiche_produit`, `url_image`, `prix_ttc`, `ecotaxe_ttc`, `frais_port_ttc`, `disponibilite`, `ean`, `reference_constructeur`, `description`, `marque`, `garantie`, `date_time_creation`, `date_time_modification`, `actif_non_actif`) 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();
}
}
fclose($handle);
MYSQL_CLOSE();
?> |
Partager