Created
July 8, 2011 11:51
-
-
Save pkdavies/1071669 to your computer and use it in GitHub Desktop.
fgetcsv to mysql insert statements
This file contains hidden or 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
<pre> | |
<?php | |
$row = 0; | |
if (($handle = fopen("data.csv", "r")) !== FALSE) { | |
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | |
$num = count($data); | |
$model_id = $data[1]; | |
for ($c=2; $c < $num; $c++) { | |
if (!empty($data[$c])){ | |
echo "INSERT INTO `test_report_fields_to_model` (`test_report_fields_id`, `model_id`) VALUES ($data[$c], $model_id);\n"; | |
} | |
} | |
$row++; | |
} | |
fclose($handle); | |
} | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment