source: src/db/csv_to_db.php@ 8946

Last change on this file since 8946 was 8946, checked in by dennisw, 14 years ago

db - map toegevoegd voor database zaken
create.sql - database op het moment
csv_to_db - leest data uit .csv bestand naar database met wat aanpassingen

File size: 870 bytes
Line 
1<?php
2
3// edit with personal settings
4function 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}
11connectdb();
12
13// .csv file to open
14if (($handle = fopen("file.csv", "r")) !== FALSE) {
15 while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
16 $lat=str_replace("N ", "", $data[0]);
17 $lon=str_replace("E ", "", $data[1]);
18 $enc = substr($data[8], -2, 1);
19 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')");
21 if (!$query) {
22 die('Invalid query: ' . mysql_error());
23 }
24 }
25 fclose($handle);
26}
27
28?>
Note: See TracBrowser for help on using the repository browser.