Changeset 9028 for src/django_gheat/csv_to_db.php
- Timestamp:
- Apr 7, 2011, 1:25:48 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/csv_to_db.php
r9006 r9028 2 2 3 3 // edit with personal settings 4 $location = ''; 5 $username = ''; 6 $password = ''; 7 $database = ''; 8 9 $filelist = array(); 10 $filelist = scandir("csv"); 11 sort($filelist); 12 unset($filelist[0]); 13 unset($filelist[1]); 14 unset($filelist[2]); 15 4 $location = '127.0.0.1'; 5 $username = 'root'; 6 $password = 'password'; 7 $database = 'project_heatmap'; 16 8 17 9 // connect to database … … 25 17 foreach($filelist as $file) { 26 18 27 $table = "gheat_ points";19 $table = "gheat_meting"; 28 20 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) { 21 if (($handle = fopen("wleiden.csv", "r")) !== FALSE) { 45 22 while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) { 46 23 $lat=str_replace("N ", "", $data[0]); … … 48 25 $ssid=str_replace("'", "", $data[2]); 49 26 $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')"); 27 $query=mysql_query("INSERT INTO ".$table." (lat, long) VALUES ('$lat','$lon')"); 52 28 if (!$query) { 53 29 die('Invalid query: ' . mysql_error()); … … 55 31 } 56 32 fclose($handle); 57 rename("csv/".$file, "csv/backup/".$file);58 33 } 59 34
Note:
See TracChangeset
for help on using the changeset viewer.