-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
50 lines (44 loc) · 1.71 KB
/
import.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
43
44
45
46
47
48
49
<?php
//importa i farmaci dall'elenco AIFA
//formattare il CSV in modo che le prime tre colonne siano ATC,principio attivo,nome
function escapetrim($value) {
return mysqli_real_escape_string($GLOBALS["dbcon"],trim($value));
}
$GLOBALS["dbcon"]=@mysqli_connect($dbhost, $dbuser, $dbpass);
$row = 1;
if (($handle = fopen("listefarmaci/a.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if (strpos($data[2],'*')!==false) {
$data[2] = substr($data[2], 0, strpos($data[2], '*'));
$data = array_map('escapetrim', $data);
}
else $data[2]="";
if ($data[0] && $data[1] && $data[2])
mysqli_query($GLOBALS["dbcon"],"INSERT IGNORE INTO farmaci (ATC, principio_attivo, nome) VALUES ('{$data[0]}','{$data[1]}','{$data[2]}')");
}
fclose($handle);
}
$row = 1;
if (($handle = fopen("listefarmaci/h.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if (strpos($data[2],'*')!==false) {
$data[2] = substr($data[2], 0, strpos($data[2], '*'));
$data = array_map('escapetrim', $data);
}
else $data[2]="";
if ($data[0] && $data[1] && $data[2])
mysqli_query($GLOBALS["dbcon"],"INSERT IGNORE INTO farmaci (ATC, principio_attivo, nome) VALUES ('{$data[0]}','{$data[1]}','{$data[2]}')");
}
fclose($handle);
}
$row = 1;
if (($handle = fopen("listefarmaci/c.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
if ($data[0] && $data[1] && $data[2])
mysqli_query($GLOBALS["dbcon"],"INSERT IGNORE INTO farmaci (ATC, principio_attivo, nome) VALUES ('{$data[0]}','{$data[1]}','{$data[2]}')");
}
fclose($handle);
}