-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsing_csv.php
42 lines (30 loc) · 1.06 KB
/
parsing_csv.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
33
34
35
36
37
38
39
40
41
42
<?php
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'koneksi'.DIRECTORY_SEPARATOR.'koneksi.php';
$flag = 0;
//$array[] = '';
if (($open = fopen("databases.csv", "r")) !== FALSE) {
while (($data = fgetcsv($open, 1000, ",")) !== FALSE) {
$array[] = $data;
}
fclose($open);
$flag = 1;
}
if ($flag == 1) {
$koneksi = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_DATABASE);
if ($koneksi->connect_errno) {
echo "Connection Error: " . $koneksi->connect_error;
}
$sizeCSV = (int) sizeof($array) - 1;
for ($i = 0; $i < $sizeCSV+1; $i++) {
$item_code = (string) $array[$i][0];
$packaging_name = (string) $array[$i][1];
$supplier_name = (string) $array[$i][2];
$sqlInsertData = "INSERT INTO `tbl_data_item_botol`(`id_item`, `item_code`, `packaging_name`, `supplier_name`) VALUES ('NULL', '$item_code', '$packaging_name', '$supplier_name' )";
$hasil = $koneksi -> query($sqlInsertData);
if (!$hasil) {
echo $i." GAGAL INSERT";
break;
}
}
}
?>