导入的CSV缺少字段

时间:2014-05-13 09:31:01

标签: php mysql csv yii load-data-infile

我必须从Yii导入一个CSV文件到MySQL。这是我的问题:

$sql = "LOAD DATA LOCAL INFILE '".addslashes($dir)."'
        INTO TABLE `card`
        FIELDS
        TERMINATED BY ','
        ENCLOSED BY '\"'
        LINES
        TERMINATED BY '\n'
        IGNORE 1 LINES
        (`ID_CARD`,`SERIAL_NO`,`SERIAL_NO_CARD`,`ICCID`,`MSISDN`,`SITE_NAME`,`STATUS`,`DATE_HISTORY`)";
Yii::app()->db->createCommand($sql)->execute();

但是,只插入了列ID_CARD

我做错了什么?

我已经在PHPMyAdmin上对此进行了测试,但它做了同样的事情。

example data

1 个答案:

答案 0 :(得分:0)

试试这个,

LOAD DATA LOCAL INFILE 'test.csv' 
INTO TABLE card FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n' IGNORE 1
LINES (ID_CARD,SERIAL_NO,SERIAL_NO_CARD,ICCID,MSISDN,SITE_NAME,STATUS,DATE_HISTORY)