using php take initial line csv record emanate mysql list data


i am perplexing take rather infinite csv record insert mysql database referencing project. i initial line record emanate list controlling repremand information forms varchar any column. ultimate idea automate slight i have several identical files nonetheless any opposite information opposite volume "columns" csv files. problem i am carrying gettype() returning 'string' any buttress instead int, boyant twine i to.



platform php 5, os ubuntu 8.04



here formula far:



<?php

// beget list initial line csv file

$inputfile = 'file.csv';
$tablename = 'file_csv';

$fh = fopen($inputfile, 'r');
$contents = fread($fh, 5120); // 5kb
fclose($fh);

$filelines = explode("\n", $contents); // raze certain wholly controlling initial line.

$fieldlist = explode(',', $filelines[0]); // removed columns, put array
echo 'create list exists `'.$tablename.'` ('."<br/>\n";
for($i = 0; $i <= count($fieldlist); $i++)
{
switch(gettype($fieldlist[$i])) {
box 'integer':
$typeinfo = 'int(11)';
break;
box 'float':
$typeinfo = 'float';
break;
box 'string':
$typeinfo = 'varchar(80)';
break;
default:
$typeinfo = 'varchar(80)';
break;
}
if(gettype($fieldlist[$i]) != null) relate "\t".'`'.$i.'` '.$typeinfo.' null, --'.gettype($fieldlist[$i]).' '.$fieldlist[$i]."<br/>\n";
}
echo ' primary pivotal (`0`)'."<br/>\n";
echo ') engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;';


example initial line:
1,0,0,0,0,0,0,0,0,0,0,0,0.000000,0.000000,0,0,0,,0,0,1,0,50,'word remember (old)',



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?