Skip to content

Instantly share code, notes, and snippets.

@dmdevoss
Last active August 29, 2015 14:00
Show Gist options
  • Save dmdevoss/11261926 to your computer and use it in GitHub Desktop.
Save dmdevoss/11261926 to your computer and use it in GitHub Desktop.
skeleton to a csv->mysql db migration in php
<?php
$connect = new PDO('mysql:host=localhost;dbname=db',"user","pass");
$file = fopen("myCSVFile.cvs", 'r');
do {
if ($data[0]) {
$connect->exec("INSERT INTO myTable (col1, col2, col3, col4, col5) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."'
)
");
}
} while ($data = fgetcsv($file,1000,",","'"));
die;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment