|
@@ -12,6 +12,9 @@ if(!$f) die("Cannot open file");
|
|
|
$line=trim(fgets($f,65535));
|
|
|
$words=explode(FIELD_SEP, $line);
|
|
|
|
|
|
+$fields_count = count($words);
|
|
|
+
|
|
|
+print "DROP TABLE IF EXISTS `".$tablename."`;\n";
|
|
|
print "CREATE TABLE `".$tablename."` (\n";
|
|
|
print "\t`".implode("` varchar(255),\n\t`", $words).'` varchar(255)';
|
|
|
print "\n);\n\n";
|
|
@@ -20,22 +23,26 @@ $fieldsstr='`'.implode("`,`",$words).'`';
|
|
|
|
|
|
$linen=0;
|
|
|
while(!feof($f)) {
|
|
|
- if(!($linen%ROWSPERLINE))
|
|
|
- $outline = 'INSERT INTO `'.$tablename.'` ('.$fieldsstr.')VALUES';
|
|
|
- $outline .= '(';
|
|
|
-
|
|
|
- $line = str_replace('"', '\"', trim(fgets($f, 65536)));
|
|
|
- $words=explode(';', $line);
|
|
|
- $outline .='"'.implode('","',$words).'"';
|
|
|
-
|
|
|
- $outline .= "),";
|
|
|
- $linen++;
|
|
|
- if(!($linen%ROWSPERLINE))
|
|
|
- print substr($outline, 0, -1).";\n";
|
|
|
+ if(!($linen%ROWSPERLINE))
|
|
|
+ $outline = 'INSERT INTO `'.$tablename.'` ('.$fieldsstr.')VALUES';
|
|
|
+ $outline .= '(';
|
|
|
+
|
|
|
+ $line = str_replace('"', '\"', trim(fgets($f, 65536)));
|
|
|
+ $words = explode(FIELD_SEP, $line);
|
|
|
+
|
|
|
+ while (count($words) < $fields_count)
|
|
|
+ $words[] = '';
|
|
|
+
|
|
|
+ $outline .='"'.implode('","',$words).'"';
|
|
|
+
|
|
|
+ $outline .= "),";
|
|
|
+ $linen++;
|
|
|
+ if(!($linen%ROWSPERLINE))
|
|
|
+ print substr($outline, 0, -1).";\n";
|
|
|
}
|
|
|
|
|
|
if($linen%ROWSPERLINE)
|
|
|
- print substr($outline, 0, -1).";\n";
|
|
|
+ print substr($outline, 0, -1).";\n";
|
|
|
|
|
|
fwrite(STDERR, "rows: ".$linen."\n");
|
|
|
|