php while循环使用wamp并将csv发送到sql

php while循环使用wamp并将csv发送到sql,php,sql,loops,csv,wamp,Php,Sql,Loops,Csv,Wamp,我有以下文件: <?php require_once "conectar_a_base_de_dados.php"; $file = "todos_cp.csv"; if( file_exists($file) ) { $fh = fopen($file, "r"); while ($line = fgetcsv($fh, 1000, ";")) { $id_d = $line[0]; $id_c = $line[1]; $id_f = $line[2]; $freg = $line[

我有以下文件:

<?php
require_once "conectar_a_base_de_dados.php";
$file = "todos_cp.csv";

if( file_exists($file) )
{
$fh = fopen($file, "r");

while ($line = fgetcsv($fh, 1000, ";"))
{
$id_d = $line[0];
$id_c = $line[1];
$id_f = $line[2];
$freg = $line[3];

$sql = mysql_query("INSERT INTO freguesias (codigo_distrito, codigo_concelho, codigo_freguesia, freguesias)
VALUES('$id_d','$id_c','$id_f','$freg')");
}

fclose($fh);
}
?>

我假设在那些“AGADÃO”值之后有换行符?我在我的电脑上运行了这个代码,它运行得很好。与其插入MySQL,不如尝试使用print\r($line)来查看您得到了什么。我现在就试试……是的,有newlineit返回了很多混合数组!打印(第[0]行);为$id\u d提供正确的值
01;01;249;Alcafaz;;;;;;;;;;;3750;011;AGADÃO
01;01;250;Caselho;;;;;;;;;;;3750;012;AGADÃO
01;01;251;Corga da Serra;;;;;;;;;;;3750;013;AGADÃO
01;01;252;Foz;;;;;;;;;;;3750;014;AGADÃO
01;01;253;Guistola;;;;;;;;;;;3750;015;AGADÃO