Start graph and import refactoring
[contractdashboard.git] / admin / importUNSPSC.php
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
<?php
  include_once("../lib/common.inc.php");
      $success = 0;
      $fname = "UNSPSC_ECCMA_V13.2_UNDP_V7.csv";
      echo " ============== $fname  ============== <br>";
      flush();
      $row = 1;
      $handle = fopen($path . $fname, "r");
      $headers;
      
      while (($data = fgetcsv($handle, 1000)) !== false) {
          $num = count($data);
          
          if ($row == 3) {
              $headers = $data;
          } elseif ($row > 3) {
//print_r($data);
$query = 'insert into "UNSPSCcategories" values(".$data[1].","$data[2]");';             
//echo $query."<br>\n";         
$conn->exec($query);
              flush();
              
              //echo "<hr>\n";
          }
          
          $row++;
      }
      echo "<br> $success records successfully created";
      flush();
      fclose($handle);
?>