Changeset 8968
- Timestamp:
- Mar 16, 2011, 11:26:10 AM (14 years ago)
- Location:
- src/db
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/db/create.sql
r8946 r8968 1 CREATE TABLE ` project_heatmap`.`test_1` (1 CREATE TABLE `db`.`tbl` ( 2 2 `latitude` double(9,7) NOT NULL, 3 3 `longitude` double(9,7) NOT NULL, -
src/db/csv_to_db.php
r8946 r8968 2 2 3 3 // edit with personal settings 4 function connectdb() 5 { 6 mysql_connect("location", "username", "password") 7 or die("Error connecting to mysql: " . mysql_error()); 8 mysql_select_db('database') 9 or die("Error connecting to database: " . mysql_error()); 10 } 11 connectdb(); 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 12 32 13 33 // .csv file to open 14 if (($handle = fopen( "file.csv", "r")) !== FALSE) {34 if (($handle = fopen($file, "r")) !== FALSE) { 15 35 while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) { 16 36 $lat=str_replace("N ", "", $data[0]); … … 18 38 $enc = substr($data[8], -2, 1); 19 39 echo "\"".$lat.", ".$lon."\", \"".$data[2]."\", \"".$data[4]."\", \"".$enc."\"<br />\n"; 20 $query=mysql_query("INSERT INTO test_1(latitude, longitude, ssid, mac, encryption) VALUES ('$lat','$lon','$data[2]','$data[4]','$enc')");40 $query=mysql_query("INSERT INTO ".$table." (latitude, longitude, ssid, mac, encryption) VALUES ('$lat','$lon','$data[2]','$data[4]','$enc')"); 21 41 if (!$query) { 22 42 die('Invalid query: ' . mysql_error());
Note:
See TracChangeset
for help on using the changeset viewer.