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
   |  
/// Fonction connexion à la BDD
	function connexion_bdd() {
		try {
			$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
			if ($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_NAME"] == "127.0.0.1") {
				$bdd = new PDO('mysql:host=localhost;dbname=xxxxxxx', 'xxxxxxx', 'xxxxxx', $pdo_options);
			}
			else {
				$bdd = new PDO('mysql:host=mysql51-34.bdb;dbname=xxxxxxxx', 'xxxxxx', 'xxxxxxx', $pdo_options);
			}
		}
		catch(Exception $e) {
			die('Erreur : '.$e->getMessage());
		}
		return $bdd;
	}
 
 
/// Partie du fichier pour la MAJ de la BDD
				$bdd = connexion_bdd();
 
				$req = "TRUNCATE TABLE temp; ";
				if ($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_NAME"] == "127.0.0.1") {
					$req .= "LOAD DATA INFILE 'SITE_utf8.txt' ";
				}
				else {
					$req .= "LOAD DATA LOCAL INFILE 'SITE_utf8.txt' ";
				}
				$req .= "REPLACE INTO TABLE temp ";
 
////////////////////////////////////// Cette ligne !!!!
				$req .= "FIELDS ESCAPED BY '\\' ";
 
				$req .= "IGNORE 1 LINES ;";
				$bdd->query($req);
 
				$bdd->query("TRUNCATE TABLE categories;");
				$req_categories = "INSERT INTO categories (groupe_produit, cat, sub_cat) SELECT DISTINCT num_groupe, cat, sub_cat FROM temp;";
				$reponse_categories = $bdd->query($req_categories);
 
				$bdd->query("TRUNCATE TABLE articles;");
				$req_articles = "INSERT INTO articles (num, description, groupe, life_cycle_code) SELECT num_art, description, num_groupe, life_cycle_code FROM temp;";
				$reponse_articles = $bdd->query($req_articles);
 
				// On vide la table temporaire
				$bdd->query("TRUNCATE TABLE temp;");
 
				echo 'Mise à jour des tables "categories" et "articles" effectué !'; | 
Partager