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