1 | <?php
|
---|
2 |
|
---|
3 | // edit with personal settings
|
---|
4 | $location = 'localhost:3306';
|
---|
5 | $username = 'root';
|
---|
6 | $password = 'dsql';
|
---|
7 | $database = 'project_heatmap';
|
---|
8 |
|
---|
9 | $filelist = array();
|
---|
10 | $filelist = scandir("csv");
|
---|
11 | sort($filelist);
|
---|
12 | unset($filelist[0]);
|
---|
13 | unset($filelist[1]);
|
---|
14 | unset($filelist[2]);
|
---|
15 |
|
---|
16 |
|
---|
17 | // connect to database
|
---|
18 | mysql_connect($location, $username, $password)
|
---|
19 | or die("Error connecting to mysql: " . mysql_error());
|
---|
20 | mysql_select_db($database)
|
---|
21 | or die("Error connecting to database: " . mysql_error());
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 | foreach($filelist as $file) {
|
---|
26 |
|
---|
27 | $table = substr($file, 0, -4);
|
---|
28 |
|
---|
29 | // create table
|
---|
30 | mysql_query("
|
---|
31 | CREATE TABLE IF NOT EXISTS ".$table." (
|
---|
32 | latitude double(9,7) NOT NULL,
|
---|
33 | longitude double(9,7) NOT NULL,
|
---|
34 | ssid varchar(45) NOT NULL,
|
---|
35 | mac varchar(45) NOT NULL,
|
---|
36 | encryption tinyint(4) NOT NULL,
|
---|
37 | ID int(11) NOT NULL AUTO_INCREMENT,
|
---|
38 | PRIMARY KEY (ID)
|
---|
39 | )
|
---|
40 | ");
|
---|
41 |
|
---|
42 |
|
---|
43 | // .csv file to open
|
---|
44 | if (($handle = fopen("csv/".$file, "r")) !== FALSE) {
|
---|
45 | while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
|
---|
46 | $lat=str_replace("N ", "", $data[0]);
|
---|
47 | $lon=str_replace("E ", "", $data[1]);
|
---|
48 | $ssid=str_replace("'", "", $data[2]);
|
---|
49 | $enc = substr($data[8], -2, 1);
|
---|
50 | echo "\"".$lat.", ".$lon."\", \"".$data[2]."\", \"".$data[4]."\", \"".$enc."\"<br />\n";
|
---|
51 | $query=mysql_query("INSERT INTO ".$table." (latitude, longitude, ssid, mac, encryption) VALUES ('$lat','$lon','$ssid','$data[4]','$enc')");
|
---|
52 | if (!$query) {
|
---|
53 | die('Invalid query: ' . mysql_error());
|
---|
54 | }
|
---|
55 | }
|
---|
56 | fclose($handle);
|
---|
57 | rename("csv/".$file, "csv/backup/".$file);
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | ?>
|
---|