-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
50 lines (41 loc) · 1.24 KB
/
update.php
File metadata and controls
50 lines (41 loc) · 1.24 KB
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once "db.php";
// Reading CSV
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$result = fgetcsv($file_handle, 1024);
if ($result !== false) {
$line_of_text[] = $result;
}
}
fclose($file_handle);
return $line_of_text;
}
// Set path to CSV file
$csvFile = 'csv/test.csv';
$csvArray = readCSV($csvFile);
unset($csvArray[0]);
echo "<pre>";
echo "Creating Array...<br/>";
$moduleList = array();
foreach ($csvArray as $key => $modules) {
$moduleList[$key]['Year'] = isset($modules[0]) ? $modules[0] : '';
$moduleList[$key]['Make'] = isset($modules[1]) ? $modules[1] : '';
$moduleList[$key]['Model'] = '1.6';
$moduleList[$key]['Length'] = '1';
}
echo "Updating database...<br/>";
foreach ($moduleList as $module) {
$insert = "INSERT INTO demo (Year, Make, Model, Length
) VALUES ('".$module['Year']."', '".$module['Make']."', '".$module['Model']."', '".$module['Length']."')";
$select = "SELECT id FROM demo WHERE Make='".$module['Make']."'";
$getRow = Db::Connect()->query($select);
if (!$getRow->num_rows) {
Db::Connect()->query($insert);
}
}
echo ("Successfully udpated.<br/>");
die;