Created
June 24, 2014 14:57
-
-
Save sobstel/448fe080a52286a8e7ec to your computer and use it in GitHub Desktop.
Convert CSV to SQL INSERT statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = $argv[1]; | |
$table = $argv[2]; | |
$ls = file($file); | |
$out = ""; | |
foreach ($ls as $l) { | |
$d = str_getcsv(trim($l)); | |
$q = sprintf('INSERT INTO `%s` VALUES ("%s");', $table, implode('","', $d)).PHP_EOL; | |
echo $q; | |
$out .= $q; | |
} | |
file_put_contents($table.'.sql', $out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to skip or ignore the first line, which is the header, how do I go about that?