<?php

// edit with personal settings
function connectdb()
{
 mysql_connect("location", "username", "password")
  or die("Error connecting to mysql: " . mysql_error());
 mysql_select_db('database')
  or die("Error connecting to database: " . mysql_error());
}
connectdb();

// .csv file to open
if (($handle = fopen("file.csv", "r")) !== FALSE) {
	while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
		$lat=str_replace("N ", "", $data[0]);
		$lon=str_replace("E ", "", $data[1]);
		$enc = substr($data[8], -2, 1);
		echo "\"".$lat.", ".$lon."\", \"".$data[2]."\", \"".$data[4]."\", \"".$enc."\"<br />\n";
		$query=mysql_query("INSERT INTO test_1 (latitude, longitude, ssid, mac, encryption) VALUES ('$lat','$lon','$data[2]','$data[4]','$enc')");
		if (!$query) {
			die('Invalid query: ' . mysql_error());
		}
	}
	fclose($handle);
}

?>