我必须从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上对此进行了测试,但它做了同样的事情。
答案 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)