SHARE
TWEET

problem

a guest Oct 4th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. require_once('/home/protfqip/wawi/Util/Util.php');
  4.  
  5.     /**
  6.     * Author: Aleksandar Arsic
  7.     * Description: Insert CSV data into Database
  8.     * Creation Date: 2017/09/30 (yyyy/mm/dd)
  9.     */
  10.    
  11.         $counter = 0;
  12.         $updateCounter = 0;    
  13.         $servername = "localhost";
  14.         $username = "protfqip_esales";
  15.         $password = "protfqip_dek39";
  16.         $dbname = "protfqip_wawi";
  17.        
  18.         $arr = [];
  19.         $values = [];
  20.        
  21.                
  22.         $table_name = "WAWILieferant_DGH1";
  23.         $csvfile = "DGH-20792888.CSV";
  24. $row = 1;
  25. if (($handle = fopen("$csvfile", "r")) !== FALSE) {
  26.     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  27.     $i = 0;
  28.         $num = count($data);      
  29.         $row++;
  30.         for ($c=0; $c < $num; $c++) {
  31.           array_push($arr, $data[$c]);;
  32.         }
  33.     }
  34.     fclose($handle);
  35. }
  36.  
  37.  
  38.         $conn = new mysqli($servername, $username, $password, $dbname);
  39.        
  40.         if ($conn->connect_error) {
  41.              die("Connection failed: " . $conn->connect_error);
  42.         }
  43.    
  44.     for($i = 1;$i< count($arr); $i++) {
  45.     $values = explode(";", $arr[$i]);
  46.     for($j = 0; $j < count($values);$j++) {
  47.         if($values[$j] == '') {$values[$j] = "";}
  48.     }
  49.  
  50.    
  51.      $sql = "INSERT INTO `$table_name` (`artikelnr`,`artikelgruppe`, `artikelgruppenbez`,`artikelbez`,`lieferanten_name`,`lieferanten_artikelnummer`,`ean_nummer_one`,`ean_nummer_two`,`ean_nummer_three`,`ean_nummer_four`,`ean_nummer_five`,`ean_nummer_six`,`netto_ek`,`unverbindl_vkp`,`vorgeschlagener_vkp`,`verfugbarkeit_tendenz`,`verfugbarkeit_step`,`neue_preise_markieren`,`preisanderungen_kennzeichen`,`auslistungen_kennzeichen`,`streetpreis`,`grundpreis`,`partner_programm`,`gewicht_in_kg`,`lange_in_mm`,`breite_in_mm`,`hohe_in_mm`,`spedition`,`no_reporting`,`no_reporting_sony`)
  52.    VALUES ('$values[0]','$values[1]','$values[2]','$values[3]','$values[4]','$values[5]','$values[6]','$values[7]','$values[8]','$values[9]','$values[10]','$values[11]','$values[12]','$values[13]','$values[14]','$values[15]','$values[16]','$values[17]','$values[18]','$values[19]','$values[20]','$values[21]','$values[22]','$values[23]','$values[24]','$values[25]','$values[26]','$values[27]','$values[28]','$values[29]')
  53.     ON DUPLICATE KEY UPDATE `artikelgruppe` = '".$conn->real_escape_string(trim($values[1]))."', `artikelgruppenbez` = '".$conn->real_escape_string(trim($values[2]))."', `artikelbez` = '".$conn->real_escape_string(trim($values[3]))."', `lieferanten_name` = '".$conn->real_escape_string(trim($values[4]))."', `lieferanten_artikelnummer` = '".$conn->real_escape_string(trim($values[5]))."', `ean_nummer_one` = '".$conn->real_escape_string(trim($values[6]))."', `ean_nummer_two` = '".$conn->real_escape_string(trim($values[7]))."', `ean_nummer_three` = '".$conn->real_escape_string(trim($values[8]))."', `ean_nummer_four` = '".$conn->real_escape_string(trim($values[9]))."', `ean_nummer_five` = '".$conn->real_escape_string(trim($values[10]))."', `ean_nummer_six` = '".$conn->real_escape_string(trim($values[11]))."', `netto_ek` = '".$conn->real_escape_string(trim($values[12]))."', `unverbindl_vkp` = '".$conn->real_escape_string(trim($values[13]))."', `vorgeschlagener_vkp` = '".$conn->real_escape_string(trim($values[14]))."', `verfugbarkeit_tendenz` = '".$conn->real_escape_string(trim($values[15]))."', `verfugbarkeit_step` = '".$conn->real_escape_string(trim($values[16]))."',`neue_preise_markieren` = '".$conn->real_escape_string(trim($values[17]))."', `preisanderungen_kennzeichen` = '".$conn->real_escape_string(trim($values[18]))."', `auslistungen_kennzeichen` = '".$conn->real_escape_string(trim($values[19]))."', `streetpreis` = '".$conn->real_escape_string(trim($values[20]))."', `grundpreis` = '".$conn->real_escape_string(trim($values[21]))."', `partner_programm` = '".$conn->real_escape_string(trim($values[22]))."', `gewicht_in_kg` = '".$conn->real_escape_string(trim($values[23]))."', `lange_in_mm` = '".$conn->real_escape_string(trim($values[24]))."', `breite_in_mm` = '".$conn->real_escape_string(trim($values[25]))."', `hohe_in_mm` = '".$conn->real_escape_string(trim($values[26]))."', `spedition` = '".$conn->real_escape_string(trim($values[27]))."', `no_reporting` = '".$conn->real_escape_string(trim($values[28]))."', `no_reporting_sony` = '".$conn->real_escape_string(trim($values[29]))."'";
  54.    
  55.    if($conn->query($sql) == TRUE) {
  56.     $counter++;
  57.    } else {
  58.      echo "Error: " . $sql . "<br>" . $conn->error;
  59.    }
  60.    
  61.     }
  62.  
  63.    
  64.     echo  $counter . " new implemented and " . $updateCounter . " updated.";
  65.     $counter = 0;
  66.     $updateCounter = 0;
  67.  
  68.    
  69.    
  70.  
  71.  
  72. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top