Changeset 8968 for src/db


Ignore:
Timestamp:
Mar 16, 2011, 11:26:10 AM (14 years ago)
Author:
dennisw
Message:

csv_to_db.php - vars aanpassen voor gebruik
create.sql - db en tbl aangepast voor gemak

Location:
src/db
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/db/create.sql

    r8946 r8968  
    1 CREATE TABLE `project_heatmap`.`test_1` (
     1CREATE TABLE `db`.`tbl` (
    22  `latitude` double(9,7) NOT NULL,
    33  `longitude` double(9,7) NOT NULL,
  • src/db/csv_to_db.php

    r8946 r8968  
    22
    33// 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
     13mysql_connect($location, $username, $password)
     14        or die("Error connecting to mysql: " . mysql_error());
     15mysql_select_db($database)
     16        or die("Error connecting to database: " . mysql_error());
     17
     18       
     19// create table
     20mysql_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
    1232
    1333// .csv file to open
    14 if (($handle = fopen("file.csv", "r")) !== FALSE) {
     34if (($handle = fopen($file, "r")) !== FALSE) {
    1535        while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
    1636                $lat=str_replace("N ", "", $data[0]);
     
    1838                $enc = substr($data[8], -2, 1);
    1939                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')");
    2141                if (!$query) {
    2242                        die('Invalid query: ' . mysql_error());
Note: See TracChangeset for help on using the changeset viewer.